Skip to main content

Database Connection Issue in cPanel Cron Job

Comments

11 comments

  • quietFinn

    Does it work if you run that in command line as user username1 ?

    Have you checked that database settings are correct in configuration.php ?

    I don't understand why you want to run that in cron job, isn't that meant to be used when figuring out problems in WHMCS?

     

     

    0
  • omid chahardoli

    1- Yes, if I grant Normal Shell access to the user username1, everything runs smoothly, and I ultimately receive the message [OK] Completed.

    2- Yes, there is no issue with the database connection and its password in the configuration.php file because the site is accessible and functioning properly. My question pertains to the problem of running a cron job in the cPanel settings.

    3- If Normal Shell access is granted to the user username1, the cron job process in cPanel runs smoothly. However, for security reasons, I prefer not to have shell access. Is there a way to achieve this?

    0
  • cPRex Jurassic Moderator

    No, the user would need shell access in order to execute that, even from cron.

    0
  • Jasmine Cat

    Hey cPRex,

    Thanks for responding to this issue, but I am having the same issue with one of my clients.

    When you say "Shell access", what do you mean by this? This is what my current crontab says from that cpanel user, using:

    su -l -s /bin/bash <CPANELUSERNAME>
    MAILTO="jasmine@myemailfortesting.com"
    SHELL="/usr/local/cpanel/bin/jailshell"
    */5 * * * * /opt/cpanel/ea-php81/root/usr/bin/php -q /home/<cpanelusername>/whmcsdata/crons/cron.php

    I set it up to email alert me, and it shows the same for WHMCS:

    <div class="error-container"><h1>Critical Error</h1><p>Could not connect to the database.</p></div>

    But when I run it manually in either the cpanelusername's bash, OR root's bash, it's fine. It also runs fine in root's crontab.
    Could it be this line causing us both issues?

    SHELL="/usr/local/cpanel/bin/jailshell"

    Thanks, Jasmine.

    0
  • cPRex Jurassic Moderator

    Jasmine Cat - can you let me know the exact line you have setup in the cron for the user?

    0
  • Jasmine Cat

    cPRex

    0
  • cPRex Jurassic Moderator

    Thanks for that - I wasn't sure if that was the exact line or now.

    Does the user have the "Normal shell" option enabled in WHM >> Manage Shell Access?

    0
  • Jasmine Cat

    It is set to normal shell now but was under the jailed section before I clicked Shell Access under the Account Functions > Modify An Account > Chose The Account > Tick The Shell Access.

    This isn't brilliant as they can do /home and ls in there to see all the cpanel users (like their username so could cause a data leak with names being shown such as domains) but that's all.

    I wish the jailed shell still allowed them to run the PHP 8.1 bin binary but I guess not and it fails to connect to the database since failing to read backwards and go to /home/<username>/public_html.

    0
  • cPRex Jurassic Moderator

    Does the tool work properly under the normal shell option, though?

    0
  • Jasmine Cat

    So by process of elimination, it's the jailed shell that causes it.

    0
  • cPRex Jurassic Moderator

    Correct - the user has to be set to full normal shell in order for this to work.

    0

Please sign in to leave a comment.