I set up cronjob with following command:
sudo crontab -e
I tried following statements for cronjob but it doesn’t work:
30 2 * * * php -q /path/to/php/script.php
30 2 * * * /usr/bin/php /path/to/php/script.php
30 2 * * * /usr/bin/php -q /path/to/php/script.php
But when I tried the GET method as follows, it works:
30 2 * * * wget http://my.domain.com/path/to/php/script.php
I have a LAMP setup Ubuntu 12.04 (64-bit) system with my PHP version manually upgraded from 5.3 - 5.4 to run modules on my WHMCS installation.
Any idea what’s going wrong while running with PHP mode? I don’t want to use GET method!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Most likely, it is looking for config scripts in a relative path.
Think of this example:
Now, if the file has something like this:
This will fail, because you are in your home directory, not in the same directory where config.inc.php resides.
Now, when you call it via a curl/wget call:
Apache will tell it that it is being executed in /path/to/, so when it looks for config.inc.php, it will find it.
Relative paths are good, but only if you fully understand how they work. If you prefer not to use wget/curl, change the cron to something like this:
Crontab executes the task using the current user that ran
crontab -e
. When you usewget
it’s handled by Apache using thewww-data
user/group pair.First, make sure the script works as expected.
Second, edit the crontab for the Apache user account
Now add the crontab and output to a log file.
I would recommend that you create a bash script to run this, and then call that with crontab.
Crontab executes the task using the current user that ran
crontab -e
. When you usewget
it’s handled by Apache using thewww-data
user/group pair.First, make sure the script works as expected.
Second, edit the crontab for the Apache user account
Now add the crontab and output to a log file.
I would recommend that you create a bash script to run this, and then call that with crontab.
This comment has been deleted