Cron Job Configuration Guide

Cron Jobs basic setup via Cpanel.

Some time you need to run a peace of code on specific time interval. Cron Jobs module is used for this work. This can be done by adding the following line via Cpanel/Cron Jobs:

/usr/local/bin/php /home/your-site-root-dir/public_html/cron-file.php

Wget Method

* * * * *   wget -q -O – ‘http://www.mydomain.com/cron.php’ >/dev/null

Note: The Cron commands may vary depending on the server configuration.

Cron Jobs setup via SSH.

-Login to your server via SSH

-Run cd [path-to-your-homedir] command to enter the root folder

-Run pwd command

-You will see the path to the root folder (e. g. /home/yoursite/public_html)

-Run which php command

-You will see the path to PHP (e. g. /usr/local/bin/php)

-Run crontab -e command

-This will open the crontab file editor

-To make changes to this file, press the i key on the keyboard

– In the bottom left corner you will see the following message: insert

You should make the Cron commands based on the paths to php and cron folder. They should look similar to the command given below:

* * * * * /usr/local/bin/php /home/your-site-root-dir/public_html/cron-file.php

* – the time when Cron runs

/usr/local/bin/php – path to PHP

/home/your-site-root-dir/public_html/ – path to Cron

cron-file.php – Cron file

After you inserted the commands, press the Escape button. The Insert message will disappear.

Type : wq – this command rewrites the Cron document and closes it.

Don’t exit SSH if you want to check whether Cron has been set up correctly. Here is how you can do that:

Copy your command (for example, /usr/local/bin/php /home/yoursite/public_html/cron-file.php) and paste it. Click Enter.

If there are no errors – the following line appears:

[root@server cron]#

This means the Cron Jobs have been set up properly.

You can find more information on Cron jobs here: http://en.wikipedia.org/wiki/Cron

Also, here are some useful articles about Cron jobs:

* adding cron jobs on Linux (http://www.unixgeeks.org/security/newbie/unix/cron-1.html)

* adding cron jobs on Windows (http://thecrumb.com/2009/08/15/cron-for-windows/)

* adding cron jobs on CPanel (http://docs.cpanel.net/twiki/bin/view/AllDocumentation/CpanelDocs/CronJobs)

If you like the post & want to get more then Subscribe our blog posts. Subscribe SunwareTech.net RSS Feed Facebook Twitter Email

 

Both comments and pings are currently closed.

2 Responses to “Cron Job Configuration Guide”

  1. Man says:

    Amazing page, I am viewing back regularly to discover updates.

  2. polo says:

    Howdy! I just would like to give a huge thumbs up for the great info you’ve gotten right here on this post. I can be coming again to your blog for extra soon.

Copyright © Sunware Technologies - Your web partner