- Your cart is currently empty.
How to Set Up Cron Jobs in cPanel
Cron Jobs allow you to automate the running of scripts. They are used to schedule jobs, for example to automate system administration or maintenance. They are also used in the development of web applications that require the periodic execution of predefined jobs in order to function.
Table of contents
- Setting up cron jobs in the cPanel control panel
- Examples of cron jobs with different commands
- How to run a PHP script with different PHP versions?
Setting up cron jobs in the cPanel control panel
To set up jobs, you first need to log in to the cPanel Control Panel and search for Cron Jobsin the Advanced icon section .
On the page that opens, you can enter your email address in the Cron Email section – under the Email setting – to which you will receive a notification each time a cron job is run that it has been successfully executed.
Under the Add New Cron Job section, set the frequency of retries. Under Common Settings, you have the most common settings (once per minute, hour, day, …). If these settings do not suit you, you can set how many times the cron job will be executed.
In the field next to Command:, enter the command to be executed at the predefined intervals.
We also advise you not to set cron jobs to execute too frequently (e.g. once per minute), as this can overload your hosting package, which can lead to website malfunctions. It is recommended to execute at most once per hour or less frequently.
Examples of cron jobs with different commands
In the command below, instead of username, type the path where your website is installed. The best way to find the path is in the cPanel dashboard, in the general information column – on the right-hand side, under Home Directory. If the site is not installed in the public_html folder, or if it is in a subfolder within public_html, you will need to add the path to the folder where the site is loaded.
Example:
/home/username/vasadomena.si/cron.php/home/username/public_html/subfolder/cron.php
The above two commands will run the cron.php file according to the intervals we set in the previous step. Different scripts (WordPress, Magento, …) may have different commands or additional parameters to be added, so we advise you to read the exact instructions.
To make it easier for you, here are some examples of cron jobs with different commands:
- with PHP *:
/usr/local/bin/php -q /home/username/public_html/path/to/url.php > /dev/null 2>&1 - with WGET:
wget --quiet -O - "http://example-domain.com/path/to/url.php" >/dev/null 2>&1 - s CURL:
curl --silent 'http://example-domain.com/path/to/url.php' >/dev/null 2>&1 - with the command line:
/bin/sh /home/vase-user-name/public_html/path/to/url.sh >/dev/null 2>&1
* To execute cron jobs via the PHP interpreter, the path to the PHP interpreter ( binary) must be specified in full, i.e. in the following format /usr/local/bin/php.
Using the abbreviated form of php via the cron mechanism results in using the PHP version“cgi-fcgi” – i.e. the same version used by the web server (Apache/LiteSpeed). In this mode, however, the $_SERVER['argv'] variable is not defined, which means that certain cron jobs do not work (e.g. because the application does not receive the given parameters).
How to run a PHP script with different PHP versions?
You can configure the version of PHP you want to use on your hosting package in the cPanel control panel (instructions). However, cron jobs running on the server will normally use the server version of PHP, not the one you have specified for your hosting package.
The Cron PHP VersionMismatch error is an error in some applications that require you to specify a specific PHP version for cron jobs. For example, this problem often occurs in the WHMCS application.
The solution is simple, as you can run PHP scripts and applications with cron jobs with a specific PHP interpreter version. If your cron job needs to run with a different version of PHP, you will achieve this by adapting the cron command.
Example of an application (script) that will run with PHP 5.6:
/opt/alt/php56/usr/bin/php -f /home/vase-user-name/directory/file.php
Various errors may occur during the execution of cron jobs. These are most often caused by incorrect settings of the cron job itself, but can also occur due to errors in the application, the web page, the active shell script, etc. Read more about locating errors in How to debug cron jobs?
For further help, please call us on 059 335 000 or email us at info@neoserv.si.



COMMENT THE POST
Your comment has been successfully submitted
The comment will be visible on the page when our moderators approve it.