Here’s my situation:
I’m trying to run a php script via cron, and I’ve got a crontab (/etc/crontab) that looks like this:
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/var/www:
MAILTO=<myemailaddress>
m h dom mon dow user command
* * * * * root /usr/bin/php /var/www/testing.php
And when I run the command /usr/bin/php /var/www/testing.php from bash/sh, everything is dandy. It’s just a basic php script that writes some gibberish to a file. However, my cronjob is not executing. I’ve used sudo service cron restart several times but all to no avail. Am I missing something obvious here?
Thanks, and cheers!
Solution
My own fault! The php script I was running was writing to a file that was not properly accessed – e.g., lacking full file paths. Thanks for the help all!
Create a shell script and put the PHP command in there. Make it executeabl and put it into the crontab.
You can then better track and change the command as well as setting up the environment (vars, paths) for the php script more easily.