4

How can I set up a php script to run via cron

I've created a file in the cron.d folder with the username as the file name:

/etc/cron.d/username

Inside of username file I placed the following cron command

0,30 * * * *   username /home/username/public_html/cron.php

I'm actually trying to get the cron working for Open Atrium however upon checking Open Atrium status it shows no signs of the cron file being run.

Any help on this would be greate

Oudin
  • 201
  • 1
  • 4
  • 10

2 Answers2

6

You can use crontab to add/remove/edit cronjobs.

Hit Alt+Ctrl+T to open terminal.

First make sure the script is executable by running:

chmod +x YOURSCRIPT

Then run the following command to add your cronjob:

crontab -e

Add your cronjob like this:

0,30 * * * * /usr/local/bin/php /home/username/public_html/cron.php

That's it!

Your can check the current user's crontab entries by running:

crontab -l

For more information about crontab run:

crontab --help

OR

man crontab
Basharat Sialvi
  • 23,936
  • 8
  • 61
  • 82
  • I still haven't gotten it to work. Question my /usr/local/bin/ folder is empty is this normal? I'm using php5-cgi – Oudin Aug 20 '12 at 23:39
  • 2
    @Oudin try `/usr/bin/php-cgi`. You can search binary packages installed on your system by running `whereis -b `, In your case `whereis -b php-cgi` – Basharat Sialvi Aug 21 '12 at 09:54
  • Thanks just found it a few hours ago but goggling php-cgi location – Oudin Aug 21 '12 at 13:56
  • In Ubuntu 16.04, PHP7: "whereis -b php7.0-cgi" result will be: "php7: /usr/bin/php7.0 .." – Sadee Apr 12 '17 at 12:09
0

Don't you also have to put the path to php?

/usr/local/bin/php /home/john/myscript.php
Peachy
  • 7,077
  • 10
  • 37
  • 45
simonsays
  • 41
  • 1
  • 2