I need step by step explanation on how to setup a cron job on my VPS server to run once every hour. I'm using Kloxo panel. And how do I know the path to the PHP interpreter?
Format:
PATH-TO-PHP -q FULL-LOCAL-PATH-TO-DOMAIN/cron.php
From a shell, run type php
. It will give you the path to the PHP interpreter. (It is probably /usr/bin/php
.):
$ type php
php is /usr/bin/php
$
To run a cronjob every hour, you'll need some entries like:
0 * * * * /usr/bin/php /path/to/whatever/cron.php
If crontab -e
doesn't give you a nice header, here's one you can copy and paste into every crontab(5)
you edit:
# m h dom mon dow command
Run this command to edit your cronjobs:
crontab -e
And a crontab file can look like this:
If you need to run more than one command, just add a new line in the similar format below. * means "all" as usual, in other words, the entry above runs /home/jarmund/crons/somescript.php "15 minutes past, all hours, all days, all months, all weekdays". To store it, just save and exit to the temporary filename that was suggested. NB: The example above assumes that the php script you want to run has the path to its interpreter set in it. If not, you need to include that in the command, such as with:
crontab -e takes you to whichever editor is set in your shell. If you don't want to use your default one for whatever reason, just:
...for example, beforehand. Assuming you use bash, that is.