My crontab states:

PATH=/var/www
00 00 * * * php -q /tasks/script1.php
*/5 * * * * php -q /cycle/script2.php
*/1 * * * * php -q /tasks/script3.php

script 1 doesnt run, but I need to to run every midnight

script 2 doesnt run but works fine when executed manually.

script 3 DOES run perfectly...

makes no sense to me - any ideas?

Dani AI

Generated

— quick diagnosis and a reproducible fix.

Most likely causes: cron can’t find the PHP binary because the crontab’s PATH is set incorrectly or the script paths are not the full filesystem paths cron expects. Cron jobs run in a minimal environment (not your shell or the webserver user), so browser execution and manual runs don’t guarantee the same environment. ’s permission point is valid (cron runs as a different user), and ’s timing-format tip is sensible — prefer the conventional 0 instead of 00.

Try these practical changes (use the exact php location on your system; which php will tell you):

0 0 * * * /usr/bin/php -q /var/www/tasks/script1.php >> /var/log/script1.log 2>&1
*/5 * * * * /usr/bin/php -q /var/www/cycle/script2.php >> /var/log/script2.log 2>&1
* * * * * /usr/bin/php -q /var/www/tasks/script3.php >> /var/log/script3.log 2>&1

Checklist to verify if problems persist:

  • Confirm which crontab you edited (crontab -e vs /etc/crontab) — system crontab needs a username field.
  • Run the exact command from the shell using the same user as cron (or sudo -u username ...) to reproduce environment errors.
  • Check cron logs: grep CRON /var/log/syslog (Ubuntu) and inspect the *.log files above for stdout/stderr.
  • Verify file ownership/permissions: scripts must be readable by the cron user; if executing directly they need +x and a proper shebang.
  • Simplify schedules while testing (use * * * * * or */1) so you get fast feedback.

These steps will narrow whether it’s an environment/path issue, a permissions/ownership problem, or a crontab-format mistake.

Recommended Answers

All 3 Replies

My first guess would be permissions on the files.

but if they run manually from any browser? Surely crontab can run them? What permissions do the files need for crontab to successfully execute them?

N.B. Cant be permissions as they all have the same

admitedly, I've never seen anyone use double-zeros in this field before. Can you try it with single 0's in the time fields?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.