Database Connection Issue in cPanel Cron Job
I'm encountering an issue with the execution of a cron job, specifically within cPanel's cron job setup. When I run the following command with root access in the command line, everything works perfectly, and there are no issues:
/opt/cpanel/ea-php73/root/usr/bin/php -q /home/username1/crmfile/crons/cron.php all -F -vvv >> /home/username1/crondebug.txt
However, when I precisely set the same command in the cPanel cron job setup with the user "username1," I get the following error in the crondebug.txt file:
<div class="error-container"><h1>Critical Error</h1><p>Could not connect to the database.</p></div>
This title includes additional information to clarify that the website is accessible and functioning correctly, and you have already performed troubleshooting and diagnostics related to WHMCS settings without finding any issues.
But this is not working only in cpanel cron job. How can I resolve this issue?
Note: I use Ubuntu 20.04.6 LTS
-
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 -
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 -
No, the user would need shell access in order to execute that, even from cron.
0 -
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.phpI 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 -
Jasmine Cat - can you let me know the exact line you have setup in the cron for the user?
0 -
0
-
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 -
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 -
Does the tool work properly under the normal shell option, though?
0 -
So by process of elimination, it's the jailed shell that causes it.
0 -
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.
Comments
11 comments