October 27, 2019
October 27, 2019
Performing the same task on your site over and over again can not only become tiring, but time-consuming as well. That’s why in this tutorial, we’ll walk you through how to set up a cron job on the hPanel.
Cron jobs let us program our system to execute simple repetitive tasks on a schedule automatically. However, though simple to use, configuring a cron job for the first time might appear somewhat confusing.
In this tutorial, we’ll cover the three main requirements for managing cron jobs: navigating the hPanel, creating a cron job, and deleting one.
Open your hPanel. Go to the Hosting column where you will find a list of all of your hosting accounts. Click the Manage button of the hosting account you want to set-up a cron job on.
Scroll down the page until you find the Advanced column. Click on the Cron Jobs button. A new window will appear.
Let’s breakdown what you need to fill in to create a cron job.
There are two options available in the TYPE section – PHP and Custom.
Selecting PHP will allow you to run .php files only, while Custom gives you the ability to execute scripts with different extensions and commands.
Second is the COMMAND TO RUN section. Here, you will write the command you want to execute.
The rest of the menus are as follows:
After you are done configuring the settings, click the Save button. If the command can successfully trace the .php file, you should see the following notification.
However, issues may occur. If that happens, there will be a pop-up message telling you where the mistake(s) has occurred.
Since a cron job will run the command automatically, you must set the timing carefully to prevent your site from overloading.
To delete a cron job, go to the same page where you created your cron job. Scroll down to the bottom. There you should see the List of Current Cron Jobs. Here, the Delete button is right below the Actions column.
Now that you know how to set up a cron job, we can try to put the theory to practice. Here are two simple examples where a cron job can automate a routine command.
Let’s create a cronjob that will clear your site’s cache.
Because the script will use a .php file, select the PHP option under the TYPE section. Next, we select the file – clear-cache.php that is located in the public_html directory. Thus, the command will be public_html/clear-cache.php.
It’s important to point out that you can also add a .php script when using the Custom option. However, the command is much simpler to set up with the PHP option.
Moving forward, let’s say we want to have the script run at midnight every single day. Under the COMMON OPTIONS, we select the Once a Day option, with 0 selected in the HOUR and MINUTE sections as shown in the screenshot above.
Save the changes and you’re done, your cron job is ready to run.
Second, let’s make a cron job that will create a regular backup of your website. Since we will use a file with a .sh extension, we will select the Custom option under the TYPE section. The backup is scheduled to run on the 15th day of every month, at 9 p.m. The options will look like this:
Just click Save and your cron job will be ready to run.
Cron jobs are handy tools that every site owner should consider learning and using. It will let the system handle repetitive tasks so that content creators can focus on other aspects of their project. And now you know how to set up a cron job.
Configuring the settings for a cron job is easier than it looks. You only need to access the hPanel and set up the time when a certain cron job should execute a script.
Now, if you want to learn more about how to set up cron jobs, here are some additional articles you should definitely check out: