Setting up CRON job using cPanel

Automation is so important these days and the following details how to create a simple cron job using CPANEL to send out a regular email. You can automate anything but I was wanting to use an example that would send me something to show that it was working. So I set up the following as an example to send out an email to myself every 5 minutes.

See also
How to Set Up and Run a Cron in CPanel

I am going to focus on a single method. The above link details how to do it using the command line on a linux server which may be helpful. I am concentrating on using the cpanel interface here.

Step 1 : Sign into your cpanel administrative panel.

Step 2 : Look to the Advanced Tab and identify the Cron Jobs Icon

Entering the Cron Jobs panel you will be presented with the following screen.

Leave the Update email button…

Step 3 : Identify the PHP script you wish to run and load it into a directory taking note of where you have noted.
(You will need to point CRON to run your specific script)

If you don’t have a script try this one. It uses the php mail function to send out a simple email to whatever target email you want which allows you to

$to_email = '';
$subject = 'Mail sent using a Cron Job Script';
$message = 'Hello and best wishes';
$headers = 'From:';

Step 4 : Save the above PHP script somewhere and load it to your server so that taking a note of where you put it.

Now I would start and set this to run up every 5 minutes just to test that it is working –

In the common settings there is s drop down which has a range of settings everything from once a minute to once a year select once every 5 minutes.

Step 6 : Set the command to be run.
Now this is the only really tricky part to the whole thing. I haven’t found a great deal of documentation on the syntax of the command that you should enter. I found two different syntaxes that seemed to work.

/usr/local/bin/php /home/youruserid/public_html/cronscripts/testrun.php


php -q /home/youruserid/public_html/cronscripts/testrun.php

Then simply hit the Add New Cron Job button and then wait for five minutes – if everything has completed successfully there will an additional line in the cron jobs listing and you will get an email every 5 minutes.

Happy Cron Jobbing.

One interesting point in my cpanel host was that you could limit the cron job to the domain which may be necessary as you become more proficient with the kind of jobs that you are wanting to run in your cron job.