How to execute a php script using cron?
I am trying to execute a php file via cron every 2 minutes, but it's not working. My crontab is:
*/2 * * * * usr/bin/php /var/www/test/cron.phpWhat am I doing wrong?
32 Answers
Check the output of which php and use the absolute path for php (in my case /usr/bin/php5).
*/2 * * * * /usr/bin/php /var/www/test/cron.phpor just
*/2 * * * * php /var/www/test/cron.phpFor clarification, the default $PATH for cron is
PATH=/usr/bin:/binYou can check the $PATH with a test entry (Source):
* * * * * env > /tmp/env.outputThus, the file
/tmp/env.outputis created.
You'll have to remove the entry * * * * * env > /tmp/env.output afterwards.
My recommendation would be to put call the script using standard web path, so you don't mingle the users and permissions, e.g. instead of doing:
/usr/bin/php <script>rather do:
/usr/bin/wget -q Then you need to make sure the script can be called just from localhost (f.e. using Apache2 access policy).
This way the cron script will be always run under the same user as the website which is a good policy to have in place.
0More in general
"Zoraya ter Beek, age 29, just died by assisted suicide in the Netherlands. She was physically healthy, but psychologically depressed. It's an abomination that an entire society would actively facilitate, even encourage, someone ending their own life because they had no hope. Th…"