Quantcast
Channel: CageFS – CloudLinux KnowledgeBase
Viewing all articles
Browse latest Browse all 13

Running PHP from cronjob

$
0
0

Issue symptoms

Some PHP scripts executed with cronjobs are not working properly, are interrupted or just hang.

Known affected website engines: Magento, CakePHP .

Cause

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/ .

Resolution

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 exporting 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|

More: https://www.directadmin.com/features.php?id=621

 


Viewing all articles
Browse latest Browse all 13

Trending Articles