Some PHP scripts executed with cronjobs are not working properly, are interrupted, or just hang. Known affected website engines: Magento, CakePHP.
The issue is caused by PHP CGI binary is being called instead of PHP CLI version. It happens due to PATH environment variable does not contain /usr/local/bin/.
There are several ways to resolve the issue depending on which panel is used or if you edit cronjob via command line. Call PHP CLI binary manually:
* * * * * /usr/local/bin/php /home/user/cronjob.php
Add /usr/local/bin/ to users crontab as:
PATH="/usr/local/bin/:/usr/bin:/bin" * * * * * php /home/user/cronjob.php
Force export path variable right before executing PHP script:
* * * * * export PATH=$PATH:/usr/local/bin; php /home/user/cronjob.php
Note 1: Engines like CakePHP use app/Console/cake wrapper to define which PHP to call. You may need to modify the file, and point to /usr/local/bin/php manually.
Note 2: On DirectAdmin panel to force specified path to be used for user cron jobs you have to create /usr/local/directadmin/data/templates/custom/cron_template.txt with the following content:
PATH=/usr/local/bin:/usr/local/sbin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin SHELL=/bin/sh MAILTO=|EMAIL| |CRONS|