Running PHP with CRON on Ubuntu
If you use crontab -e
to create cron entries ignore the missing user part.
Check the syntax for cron entries, you are missing the "user", e.g. :
3 * * * * some_user_here /usr/bin/php -q /var/www/CRON/hourly.php > /var/www/logPHP.log
Check that some_user_here as writing permissions to the log file by verifying that there are no errors when you do this:
su -m some_user_here
cd /var/www/
touch logPHP.log
Check that php executable is present where you specified by confirming that /usr/bin/php is return when you do this:
whereis php
Did you use a guide when setting up your cron entry, e.g. https://help.ubuntu.com/community/CronHowto ?
Related videos on Youtube
pyronaur
Updated on September 18, 2022Comments
-
pyronaur over 1 year
Please tell me what am I doing wrong, why doesn't this run:
3 * * * * /usr/bin/php -q /var/www/CRON/hourly.php > /var/www/logPHP.log
logPHP.log
is made, but is empty when this is run. If I replace the 3 with an*
, the script starts running but never ends.When I copy this in Terminal:
/usr/bin/php -q /var/www/CRON/hourly.php > /var/www/logPHP.log
Everything runs smoothly as it is supposed to.
Ubuntu 10.04 LTS,
PHP 5.3.2-1ubuntu4.9 with Suhosin-Patch (cli)
-
Marek Sebera almost 13 yearswhat about creating
.sh
with that command and running that script via cron? -
KingCrunch almost 13 yearsWhat do you mean by "doesn't run"? The script should start 3mins after every full hour. You are sure you didn't mixed it up with "every 3min"?
-
Admin almost 13 yearsPlease don't hate me for bringing this up but have you checked that you may have some illegal linebreaks or space characters in the cron file that my happend during copying / editing the file?
-
Admin almost 13 yearsDidn't copy the file, edited with nano. (crontab -e) @KingCrunch - I know that it won't run every 3 minutes. I change the minute value 1 minute before the next minute to test.
-
Admin almost 13 years@Marek, I was hoping to avoid that :)
-
Admin almost 13 yearsBy the way - the CRON Job RUns. I know because it creates the logPHP.log, when I open the log - it's empty (nothing at all...)
-
CodeReaper almost 13 years@Methemer Perhaps you should share the php code too, there may be something inside that is dependent on the environment in which it runs that is not present when executed by cron. Or at least make sure that you error reporting on so any potential error is printed to log.
-
-
Admin almost 13 yearsAdded the user, didn't help.
-
cjc almost 13 yearsYou need to put in the user only if you're putting files into /etc/cron.d. If you're setting up the crontab for the individual user (i.e., running "crontab -e", then the format used by Methemer is correct).
-
symcbean almost 13 yearsWhere did you get this syntax from? Cron has been around for a very long time, only /etc/crontab uses this syntax - user crontab files do not have a user field.
-
CodeReaper almost 13 yearsMethemer did not say he used crontab -e and /etc/crontab is still used (at least by me). crontab -e hides away what cron jobs that are being run and using /etc/crontab allows me to have one configuration where all cron jobs are listed and where I can specify which user should run what... and the syntax came from here help.ubuntu.com/community/CronHowto#Tips