Cron not working properly, throwing PHP Fatal errors

| | 1 min read

Recently, when I added a cron tab, I couldn't get it work no matter what I did. The file which I had to run via cron was inside the Drupal root and I added the following code to cron tab using,

  • crontab -e
  • */5 * * * * /usr/bin/php /home/user/public_html/cron-rsync.php

The above code kept triggering PHP fatal errors saying that some of the files are missing and all. In a while, I realized what I was doing wrong. I have to specify to change the directory, so that the cron could load the file! So when I re-write the crontab as per below, it worked.

*/5 * * * * /usr/bin/php cd /home/user/public_html/ && php cron-rsync.php

Hope this helps. If you have more doubts, can you please write here? Do you need any services for your drupal site, get a quote now. For more cron related articles, click here.