Home arrow Site Administration arrow Page 2 - Cron Job Tutorial: Crontab Scheduling Syntax and Script Example

Configuring Crontab to Automatically Run the Script - Administration

This is a beginner tutorial on using crontabs or cron jobs in your LAMP (Linux/Apache/MySQL and PHP) web hosting account. Crontabs can be used to automatically execute server side commands, such as a PHP script, at periodic intervals. You can specify these periodic intervals, whether you want the script to be executed hourly, daily, weekly, and so on.

  1. Cron Job Tutorial: Crontab Scheduling Syntax and Script Example
  2. Configuring Crontab to Automatically Run the Script
By: Codex-M
Rating: starstarstarstarstar / 3
December 07, 2010

print this article



First upload the PHP script to the root directory of your website. Then log in to your web hosting account. Go to the crontabs section. Bear in mind that different web hosting companies will have different methods for configuring cron.

For a common crontabs feature, such as that used by Agilityhoster and other hosting companies, take a look at the screen shot shown below:

Suppose you would like to implement the "file delete script" discussed previously, and you want to run it every 10 minutes, every hour of every day, every month, and every weekday.

First, enter the command (this is simply a full server path to the file delete script at the root directory):


Then, make sure the following items are highlighted:

  • Every 10 minutes
  • Every hour
  • Every day
  • Every month
  • Every weekday

Finally, click "Set Cron Job." When this is successful, you will receive a notice that the cron has been successfully created or added.

Screen shot:

Configure Cron Job in Go Daddy Hosting to Run PHP Scripts

Other web hosting companies, such as Go Daddy, offer a significantly different set up for setting or configuring cron jobs. If you have websites hosted in Go Daddy, follow the procedure below:

1. Log in to your web hosting account, and click "My Account."

2. Under "My Products," click "Hosting."

3. Under "Products == Web Hosting," click the "Launch" button for the website on which you would like to implement cron.

Clicking this will take you to the "Hosting Control Center."

4. In the hosting control center, go to "Content"  - "Cron Manager."

5. Click "Create Cron Job." You will then see a screen that looks like the image below:

6. Under "Cron Job title," you can assign a name to it, such as "Testcron."

7. In the "Command," Go Daddy requires the following command syntax for running PHP scripts using Cron Job:

For PHP 5 web hosting accounts:

/web/cgi-bin/php5 "$HOME/html/thisisyourphpscriptatrootdirectory.php"

For PHP 4 web hosting accounts:

/web/cgi-bin/php "$HOME/html/thisisyourphpscriptatrootdirectory.php"

Suppose you have a folder named "restricted" in your website root directory. And you would like to run a MySQL database backup script named backupmysql.php, which uses PHP 5.

Also you would like to run this backup script on an hourly basis (in reality you would set this up to run  monthly, perhaps).

This is how you will configure this cron:

Cron Job Title: Testcron
Command: /web/cgi-bin/php5 "$HOME/html/restricted/backupmysql.php"
Frequency: Hourly
Minute: x:00

Screen shot:

Securing Your Cron Scripts

The following are tips that can you use to secure your cron PHP scripts:

  1. Protect the script from direct browser execution. Of course you would not want your script to be run manually by public users using a web browser.
  2. Protect the script inside a folder that is denied public access. This will ensure that only the cron hosting feature can access it, but not public users or bots.
  3. If you are deleting files, double check the syntax and folder, because a single mistake can wipe out all of the files in your server.
  4. Remove unused cron commands, scripts and folders, because these, too, can clog and slow down your server.

>>> More Site Administration Articles          >>> More By Codex-M

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Coding: Not Just for Developers
- To Support or Not Support IE?
- Administration: Networking OSX and Win 7
- DotNetNuke Gets Social
- Integrating MailChimp with Joomla: Creating ...
- Integrating MailChimp with Joomla: List Mana...
- Integrating MailChimp with Joomla: Building ...
- Integrating MailChimp with Joomla
- More Top WordPress Plugins for Social Media
- Optimizing Security: SSH Public Key Authenti...
- Patches and Rejects in Software Configuratio...
- Configuring a CVS Server
- Managing Code and Teams for Cross-Platform S...
- Software Configuration Management
- Back Up a Joomla Site with Akeeba Backup

Developer Shed Affiliates


Dev Shed Tutorial Topics: