Ok I have been looking into cron jobs for hours, checked every post here, looked in google but I just do not understand how it works.
I have set up a cron job using my path 1 * * * * /home/myuser/domains/mysite/public_html/live.php I have also tried /home/myuser/public_html/live.php
Nothing seems to be working.
Do I have to add something in the php file (live.php)? That is the code that has to be executed. The code itself works.
I know you will all think that I am lazy but I really can’t figure this out.
*.phpis regular script file which, as any other scripting languages like i.e. perl requires interpreter to run. So if you want to run your script from command line you have either call interpreter and give it your script file as argument, like:And that’s it – it should run.
Or (if working using linux/bsd) add as very first line of your PHP script file:
which tells shell, where to look for interpreter for this script file. Please ensure your PHP is in
/usr/binfolder as this may vary depending on the distro. You can check this usingwhich, like this:if path is right, you yet need to set executable bit on script file so you’d be able to try to “launch it”:
This will make it behave as any other app, so you’d be able to launch it this way:
or from current folder:
And that’s it for that approach. It should run.
So your crontab line would look (depending on the choosen approach):
or
And you should rather use “0” not “1”, as 1st minute in hour is zero, i.e.:
EDIT
Please note cron working directory is user’s home directory. So you need to put that into consideration, which usually means using absolute pathes. Alternatively you’d prepend your call with
cd <script working path> && /usr/bin/php -q /full/....