Guide to setting up a Cron job in Cpanel

A Cron is a constantly running server process that executes specific commands at specific intervals. A Cron job is a task executed via the Cron dameon and is run by the server automatically at designated time intervals.

This article explains the steps required to set up a cron job in a Apache server running in Linux environment.

Step 1: Find out the path to PHP executable.

Create a file execpath.php – put the following code in it

$phpPath = exec(“which php”);

echo $phpPath;

Upload this file to your web servers document root. Point your browser to where this file is located – say  The output shows path to your PHP executable.

Note: Above method of getting the executable may not work in some cases. In that case try using the following paths: usr/bin/php or usr/local/bin/php. If nothing works then it is time to contact your hosting support.

Also, this script is meant to work for only Linux servers. If you are using IIS servers contact support to find the path.

Step 2: Login to Cpanel and access “Cron Jobs” tab

cron .

Step 3: Set up Cron Email

If you want to receive notification email when a Cron job is run then this is where you can configure it. Note that you will not receive any notification email if the Cron job produces no output.



Step 4: Setting up the actual Cron Job

Here you can set the timing of execution of your Cron job.

For example, if you want a Cron job executed at 1:10 AM then following configuration will apply:

For “Common Settings” select “once a day”

For “Minute” select  :10 (10)

For “Hour” select 1:00 a.m (1)

These setting vary depending on the Cron job requirements. You have to adjust accordingly.



For ‘Command’ option use the following format

[Location of your PHP executable] [options] [Location of your Cron script]

For the example Cron job, ‘Command’ option has the following value:

/usr/bin/php -q /home/<pathtomyrootdirectory>/mytest.php

Where /usr/bin/php is the path of PHP in my server. “-q” is used to suppress any output header (as my cron job does not require any output), /home/<pathtomyrootdirectory>/mytest.php is the full path to my cron script – here <pathtomyrootdirectory> is the path of my root directory and mytest.php is the cron script.

Click on the “Add a new Cron Job” to finish and save settings.



VN:F [1.9.12_1141]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.12_1141]
Rating: 0 (from 0 votes)
This entry was posted in Apache, Web Development. Bookmark the permalink. Both comments and trackbacks are currently closed.