1

I'm trying to set up a cron job via cPanel on a machine running CloudLinux/CentOS.

The command should run a PHP script every minute to update stats;

cd /home/account/public_html/phpredmin/public/ && php index.php cron/index

This is running but not updating the stats. Instead, it outputs HTML. However, the same command run via CLI as the account user works as expected by updating stats and obviously not showing any output.

2
  • 2
    There are probably already answers about command failing to run in cron (often because of missing environment variables or path). In addition on CentOS, you should also check SELinux related issues. command line is unconfined, cron might have some cron related context. – A.B Jun 29 '19 at 16:22
  • Does index.php depend on any environment variables? Is the HTML something you'd expect to be written to a file instead of outputted, or does the HTML contain an error message of some sort? – Jeff Schaller Jul 3 '19 at 17:55
0

The problem was that CLI was using the correct version of PHP to run the script, but cron was using another (wrong) version. Not sure why that happens, but the solution was to run the command slightly differently to call the correct version of PHP;

cd /home/account/public_html/phpredmin/public/ && /opt/alt/php56/usr/bin/php index.php cron/index

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.