Running PHP from cronjob

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:

Add /usr/local/bin/ to users crontab as:

Force exporting path variable right before executing PHP script:

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:

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

 

1 comment

  1. Does this possibly happen only if the “native” PHP version is not enabled in the PHP selector? Why doesn’t CloudLinux make sure the PHP CLI version being used for cron jobs is the exact version the user has selected from their control panel? I think this is an oversight.

Leave a Reply

Your email address will not be published. Required fields are marked *