How to create a cron job in cPanel

What is a cron job and how does it work?

A cron job is a task that your webserver executes every x hours, days or weeks. A cron job is also called a planned task and is used a lot in the webhosting world, it usually executes PHP scripts. Maybe you want a PHP script to update something or send you a message on a given moment of the day.

How to create a cron job?

To create a cron job, login to the cPanel of your website and type in ‘cron’ in the search area. Click on ‘Cron Jobs’, like shown in the image below.

cron job

Next you can confgure your email settings, so every time your server runs a cron job you get an email. This is a great way to test if the cron job works too.
You can also see a warning message here which says you have to know linux commands to start with these cron jobs, but if you just want to execute a PHP script you can type in ‘php -q’. So php -q /home/hostso1q/public_html/myscript.php is running myscript.php that is located in /home/hostso1q/public_html. Yes it’s that easy.

cron jobs

Now you can start putting in a command that runs every x moment. Put in the command you want to execute and choose when you want to execute it.

cron job

You can also choose an option from the drop down, which I actually recommend.

cron jobs

That’s it, you’ve created your cron job, which now executes when you want it to.

2017-07-01T19:19:07+00:00

About the Author:

Joshua
WordPress developer and founder of Hostsonny

Leave A Comment