Question

How to setup cron jobs in ubuntu + nginx?

Posted June 19, 2013 13.9k 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.

×
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 http://mydomain.com/controller/function. Is it possible?
Any idea pls..
http://ellislab.com/codeigniter/user-guide/general/cli.html

Set a cronjob that runs the following command:

php -f /path/to/index.php controller function
Create a crontab like this:
curl -v http://mydomain.com/controller/function.php >/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.
http://net.tutsplus.com/tutorials/php/managing-cron-jobs-with-php-2/
@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: http://mydomain.com/cron/sendEmail. 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.
Submit an Answer