How to create Cron Jobs on cPanel and VPS Centos 6,7


How to create Cron Jobs on cPanel and VPS Centos 6, 7 – Before entering on the topic of this article, I will explain a little about what is cron and cron function in cPanel hosting or VPS. So cron is a utility on the linux operating system to schedule a task or run a command at a time that is already in the specified or set before him. Command on cron jobs can be repeated in accordance with the settings in use and minimal looping is one minute.

How to create a Cron Job in cPanel

First I will discuss are on cPanel, please login to your account each. Then look at the Advanced menu > Cron jobs


Click the Cron jobs Cron Email menu, enter your email address to receive reports (logs) results from a cron job every time the cron job on the run.

The following menu Add New Cron Job, please create a cron job in the want. The example I made like the image below

Setting Cronjob

Examples such as the picture above I would like to run or execute the URscript.php file in the public_html directory every 5 minutes. Then click on the button Add New Cron Job to add a cron job.

How to create a Cron Job on the VPS. His first on a VPS. Please login to the server each VPS using SSH Client as root, here I was using Debian OS. Next make sure cron is already installed on the system that is in use, if not already install first by entering the following command on terminal.

#apt-get install cron

After that type the following command to add a cron job.

#crontab -e

This also applies for a computer that uses a linux operating system, is not limited only on virtual server only. If crontab is already open, the following description guide the writing of the cron job.

# Example of job definition:
# .—————- minute (0 – 59)
# |  .————- hour (0 – 23)
# |  |  .———- day of month (1 – 31)
# |  |  |  .——- month (1 – 12) OR jan,feb,mar,apr …
# |  |  |  |  .—- day of week (0 – 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# |  |  |  |  |
# *  *  *  *  * user-name command to be executed

For example I want to create a cron job to run every 1 hour once, in the crontab. Then add on the bottom line of the command like this:

0 * * * * * /home/your-directory/

The description is obvious as the above writing guide, meaning that will be executed every 1 hour, every day, every week, every month. Cron job last will run continuously every hour.

Another example of her I want to execute URscript.php (make sure php is already installed) every 1 minute then I enter the following command.

* * * * * php /opt/lampp/htdocs/script.php

We can also save a log of the results of the cron job earlier to monitor by adding the command line e.g like this

Alright so a tutorial how to use cron jobs or making good in cPanel hosting or VPS.