Question

How to setup cron jobs in ubuntu + nginx?

  • Posted June 19, 2013

I want to send schedule based php script…

Subscribe
Share

Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

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.

You can do this to run command every midnight: <br> <br>crontab -e (This opens the crontab editor) <br> <br>0 0 * * * your_command_here >/dev/null 2>&1 <br> <br>This will run your specified command at 12 AM midnight according to local server time.

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.

@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.

Thanks kamal & Mika singh. I found an excellent article. <br>http://net.tutsplus.com/tutorials/php/managing-cron-jobs-with-php-2/

Create a crontab like this: <br>curl -v http://mydomain.com/controller/function.php >/dev/null 2>&1 <br> <br>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

http://ellislab.com/codeigniter/user-guide/general/cli.html <br> <br>Set a cronjob that runs the following command: <br> <br>php -f /path/to/index.php controller function

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? <br>Any idea pls…

Does your script support running from the CLI? (“php -f /path/to/your/script.php”)