How to setup cron jobs in ubuntu + nginx?

June 19, 2013 10.1k views
I want to send schedule based php script...
8 Answers
Does your script support running from the CLI? ("php -f /path/to/your/script.php")
Thanks Kamal. My script doesn't support running from the CLI. I'm using codeigniter framework. I want to run like Is it possible?
Any idea pls..

Set a cronjob that runs the following command:

php -f /path/to/index.php controller function
Create a crontab like this:
curl -v >/dev/null 2>&1

That should do it. I am presuming you know how to create a crontab. If curl isn't installed, install it by typing: apt-get install curl
Thanks kamal & Mika singh. I found an excellent article.
@farhan.sheron that solution is over engineered for a problem as simple as yours. Just add it in manually, you don't need to code a cronjob manager in php.
Kamal, I'm confusing now. my url is working fine via CLI. Eg: I tested in cmd. Now I want to run this url everyday midnight automatically. I successfully installed ubuntu and nginx only. Now what are the steps I have to do? Thanks in advance.
You can do this to run command every midnight:

crontab -e (This opens the crontab editor)

0 0 * * * your_command_here >/dev/null 2>&1

This will run your specified command at 12 AM midnight according to local server time.
Have another answer? Share your knowledge.