How to setup cron jobs in ubuntu + nginx?

Posted June 19, 2013 14.5k views
I want to send schedule based php script...

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
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.