Difference between revisions of "Cron Configuration"

From WHMCS Documentation

m (cPanel)
 
(31 intermediate revisions by 8 users not shown)
Line 1: Line 1:
The WHMCS cron job is the process that performs all the automated actions.
+
Cron tasks must be created to automate tasks within WHMCS.
  
Just 1 single cron job needs to be setup to automate all the core functions of the system (invoicing, reminders, suspensions, etc...)
+
Cron is the name given to a system daemon used to execute tasks (in the background) at designated times. WHMCS has a number of files that are required to be run on a periodic basis in this way. All these files are located in the crons directory.
  
The cron must be configured to run no more than '''once per day'''.
+
A single cron named the '''[[Crons|System Cron]]''' automates all core functions of the system including invoicing, reminders, suspensions and other daily automation tasks.
 +
 
 +
In WHMCS 6.3.x and earlier, the system cron should be configured to run no more than '''once per day'''.
 +
 
 +
In WHMCS 7.0 and later, the system cron should be configured to run as often as every 5 minutes or as frequently as your web hosting provider will allow (for example, every 15 minutes). The shortest time interval at which WHMCS will process cron tasks is every 5 minutes.
  
 
==Setting Up Cron Jobs==
 
==Setting Up Cron Jobs==
 
 
The tutorials & screenshots below demonstrate how to configure the WHMCS cron on the most common hosting control panels.
 
The tutorials & screenshots below demonstrate how to configure the WHMCS cron on the most common hosting control panels.
  
You can obtain the exact cron command you need to use for your installation from '''Setup > Automation Settings''' at any time.
+
The system will attempt to determine the PHP path to use for your cron command. You can find this when you click on the first badge at '''Configuration (<i class="fa fa-wrench" aria-hidden="true"></i>) > System Settings > [[Automation Settings]]''' or, prior to WHMCS 8.0, '''Setup > Automation Settings'''.
  
The examples below will setup the cron to run at 9am every day.
+
[[File:Cron-configuration-badge.png|border]]
  
 
===cPanel===
 
===cPanel===
  
[[File:Videotutorial.png‎|center|link=https://www.youtube.com/watch?v=caZWco1R2kk&hd=1|Watch Video Tutorial]]
+
Click on the '''Cron Job''' icon in cPanel, select the ''Once Per Five Minutes'' option from the '''Common Settings''' menu. Then paste the cron command into the '''Command''' field.
 
 
  
Click on the '''Cron Job''' icon in cPanel, select the ''Once A Day'' option from the Common Settings dropdown menu. Then paste the cron command into the Command field.
+
Alternatively, click '''Advanced (Unix Style)''' and enter:
 
 
[[Image:Cpstandard.jpg]]
 
 
 
Alternatively click the Advanced (Unix Style) button and use the following:
 
  
 
{| class="wikitable" border="1" style="text-align:center"
 
{| class="wikitable" border="1" style="text-align:center"
Line 38: Line 36:
 
| a)
 
| a)
 
|  
 
|  
| 0
+
| */5
| 9
+
| *
 
| *
 
| *
 
| *
 
| *
 
| *
 
| *
 
|  
 
|  
| php -q /path/to/home/public_html/whmcspath/adminpath/cron.php
+
| php -q /path/to/home/public_html/whmcspath/crons/cron.php
 
|-
 
|-
 
| b)
 
| b)
 
|  
 
|  
| 0
+
| */5
| 9
+
| *
 
| *
 
| *
 
| *
 
| *
 
| *
 
| *
 
|  
 
|  
| wget -O <nowiki>http://www.yourdomain.com/whmcspath/adminpath/cron.php</nowiki> >/dev/null
+
| wget -O <nowiki>http://www.example.com/whmcspath/crons/cron.php</nowiki> >/dev/null
 
|-
 
|-
 
| c)
 
| c)
 
|  
 
|  
| 0
+
| */5
| 9
+
| *
 
| *
 
| *
 
| *
 
| *
 
| *
 
| *
 
|  
 
|  
| get <nowiki>http://www.yourdomain.com/whmcspath/adminpath/cron.php</nowiki>
+
| GET <nowiki>http://www.example.com/whmcspath/crons/cron.php</nowiki>
 
|}
 
|}
  
Line 71: Line 69:
 
The command for Direct Admin is generally the same as cPanel, however, you need to reference the full path to the php binary.
 
The command for Direct Admin is generally the same as cPanel, however, you need to reference the full path to the php binary.
  
This can be /usr/bin/php, /usr/bin/home/php or /usr/local/bin/php but this is dependent on the server setup and you should check with your Server Administrator for the full path to the php binary.
+
Depending on your server, this will be /usr/bin/php, /usr/bin/home/php or /usr/local/bin/php. Check with your hosting provider or system administrator for the full path to the PHP binary.
  
 
An example command to run is:
 
An example command to run is:
Line 77: Line 75:
 
!Command
 
!Command
 
|-
 
|-
| /usr/bin/php -q /home/demo_user/domains/testdomain.com/public_html/whmcspath/admin/cron.php
+
| /usr/bin/php -q /home/demo_user/domains/testdomain.com/public_html/whmcspath/crons/cron.php
 
|-
 
|-
| /usr/local/bin/php -q /home/demo_user/domains/testdomain.com/public_html/whmcspath/admin/cron.php
+
| /usr/local/bin/php -q /home/demo_user/domains/testdomain.com/public_html/whmcspath/crons/cron.php
 
|-
 
|-
| wget -O <nowiki>http://www.yourdomain.com/whmcspath/admin/cron.php</nowiki>
+
| wget -O /dev/null <nowiki>http://domain.tld/path/to/cron.php</nowiki>
 
|-
 
|-
| GET <nowiki>http://www.yourdomain.com/whmcspath/admin/cron.php</nowiki>
+
| GET <nowiki>http://www.example.com/whmcspath/crons/cron.php</nowiki>
 
|}
 
|}
  
[[Image:da_crons.jpg]]
+
[[File:DACron.png|border]]
  
 
===DotNetPanel===
 
===DotNetPanel===
Line 107: Line 105:
 
|C:\php\php.exe -q "C:\inetpub\wwwroot\whmcs7\admin\cron.php"
 
|C:\php\php.exe -q "C:\inetpub\wwwroot\whmcs7\admin\cron.php"
 
|-
 
|-
|"c:\program files\internet explorer\iexplore.php" "<nowiki>http://www.yourdomain.com/whmcspath/cron.php</nowiki>"
+
|"c:\program files\internet explorer\iexplore.php" "<nowiki>http://www.example.com/whmcspath/cron.php</nowiki>"
 
|}
 
|}
  
Line 116: Line 114:
 
===Plesk===
 
===Plesk===
  
You can specify the php command using the following on Linux Plesk:
+
Navigate to the Domain where WHMCS is hosted, and click on the Schedule Tasks option in the top-right menu.
  
env php -q /home/user/whmcs/admin/cron.php
+
From the Schedule Tasks page, perform the following actions:
  
[[Image:Pleskcron.jpg]]
+
# Click on the Add Task button
 +
# Set "Task type" to the "Run PHP script" option
 +
# Input the path to your cron.php script into the "Script path" field
 +
# Select PHP 5.6 or later for the "Use PHP version" option
 +
# Select the "Cron style" option from the "Run" drop-down menu
 +
# Input "*/5 * * * *" into the "Cron style" field
 +
# Click on the "OK" button
  
The Windows version of Plesk is slightly different. You need to specify the path to the php executable and then specify the path to your cron.php file.
+
{| class="wikitable" border="1" style="text-align:center"
 +
!Example "Script path" for Linux
 +
|-
 +
| /path/to/whmcs/crons/cron.php
 +
|}
 +
[[File:PleskLinCron.png|border]]
  
Check the appropriate boxes to run at the time you wish and press ok to save.
+
{| class="wikitable" border="1" style="text-align:center"
 
+
!Example "Script path" for Windows
[[Image:plesksts.jpg]]
+
|-
 +
| /path/to/whmcs/crons/cron.php
 +
|}
 +
[[File:PleskWinCron.png|border]]
  
 
===Helm===
 
===Helm===
Line 136: Line 148:
 
[[Image:interworx.jpg]]
 
[[Image:interworx.jpg]]
  
==Option Flags==
+
===Linux with no control panel===
 
 
Passing in option flags to the cron process allows you to customise the actions that get performed.  By default, all actions will run but you can pass in any of the flags below to skip or only do certain processes.
 
 
 
In WHMCS 5.2, the option flags were expanded to include '''do''' options for when you only wish to run a specific action or two as the cron runs.
 
 
 
===Flags===
 
 
 
*affcommissions
 
*affreports - First day of the month only
 
*backups
 
*cancelrequests
 
*ccexpirynotices
 
*ccprocessing
 
*clientstatussync
 
*closetickets
 
*domainrenewalnotices
 
*emailmarketing
 
*fixedtermterminations
 
*invoicereminders
 
*invoices
 
*latefees
 
*overagesbilling - Runs on the last day of the month only.
 
*suspensions
 
*terminations
 
*updatepricing
 
*updaterates
 
*usagestats
 
*skip_report
 
 
 
===How to use Option Flags===
 
Flags are passed in by simply appending them to the cron command. All the flags can be preceded with do_ or skip_. When running with do_, the cron will only complete the actions listed, everything else will be skipped. When using skip_, WHMCS will run all other commands except those defined.
 
  
====Skipping Actions====
+
Use the command to open the crontab editor:  
For example to not run CC processing you could use "php -q /home/username/public_html/admin/cron.php skip_ccprocessing" or alternatively as a browser request, like this "get http://www.yourdomain.com/admin/cron.php?skip_ccprocessing=1"
 
  
To skip multiple items the following format can be used "php -q /home/username/public_html/admin/cron.php skip_ccprocessing skip_usagestats" or alternatively "get http://www.yourdomain.com/admin/cron.php?skip_ccprocessing=1&skip_usagestats=1"
+
<tt>$ crontab -e </tt>
  
 +
On a new line enter:
  
====Doing Specific Actions====
+
<tt>*/5 * * * * php -q /path/to/home/public_html/whmcspath/crons/cron.php</tt>
In some instances, it is easier to define the actions you wish to complete rather than those you do not. For example, if you wished to take a backup of your database more regularly than once per day, you could schedule the command "php -q /home/username/public_html/admin/cron.php do_backups" or alternatively as a browser request, like this "get http://www.yourdomain.com/admin/cron.php?do_backups=1"
 
  
In this way, you can also complete actions separately that you may have skipped with a separate cron. Perhaps you want to separate when your CC processing and usage information updates are completed.
+
Type <tt>:wq</tt> and press the Enter key to save the changes to the crontab and close the editor.
To do multiple items, the following format is used "php -q /home/username/public_html/admin/cron.php do_ccprocessing do_usagestats" or alternatively "get http://www.yourdomain.com/admin/cron.php?do_ccprocessing=1&do_usagestats=1"
 

Latest revision as of 11:10, 24 May 2022

Cron tasks must be created to automate tasks within WHMCS.

Cron is the name given to a system daemon used to execute tasks (in the background) at designated times. WHMCS has a number of files that are required to be run on a periodic basis in this way. All these files are located in the crons directory.

A single cron named the System Cron automates all core functions of the system including invoicing, reminders, suspensions and other daily automation tasks.

In WHMCS 6.3.x and earlier, the system cron should be configured to run no more than once per day.

In WHMCS 7.0 and later, the system cron should be configured to run as often as every 5 minutes or as frequently as your web hosting provider will allow (for example, every 15 minutes). The shortest time interval at which WHMCS will process cron tasks is every 5 minutes.

Setting Up Cron Jobs

The tutorials & screenshots below demonstrate how to configure the WHMCS cron on the most common hosting control panels.

The system will attempt to determine the PHP path to use for your cron command. You can find this when you click on the first badge at Configuration () > System Settings > Automation Settings or, prior to WHMCS 8.0, Setup > Automation Settings.

Cron-configuration-badge.png

cPanel

Click on the Cron Job icon in cPanel, select the Once Per Five Minutes option from the Common Settings menu. Then paste the cron command into the Command field.

Alternatively, click Advanced (Unix Style) and enter:

cPanel Cron
Option Minute Hour Day Month Weekday Command
a) */5 * * * * php -q /path/to/home/public_html/whmcspath/crons/cron.php
b) */5 * * * * wget -O http://www.example.com/whmcspath/crons/cron.php >/dev/null
c) */5 * * * * GET http://www.example.com/whmcspath/crons/cron.php

Direct Admin

The command for Direct Admin is generally the same as cPanel, however, you need to reference the full path to the php binary.

Depending on your server, this will be /usr/bin/php, /usr/bin/home/php or /usr/local/bin/php. Check with your hosting provider or system administrator for the full path to the PHP binary.

An example command to run is:

Command
/usr/bin/php -q /home/demo_user/domains/testdomain.com/public_html/whmcspath/crons/cron.php
/usr/local/bin/php -q /home/demo_user/domains/testdomain.com/public_html/whmcspath/crons/cron.php
wget -O /dev/null http://domain.tld/path/to/cron.php
GET http://www.example.com/whmcspath/crons/cron.php

DACron.png

DotNetPanel

Navigate to the hosting space in which WHMCS is installed and click Scheduled Tasks from the Hosting Space Menu, then click Add Scheduled Task.

From the Task Type dropdown menu select the Check Web Site Availability option and enter the URL of the cron.php file into the URL field. Use the Schedule options to run this task Daily and finally ensure it's active and running.

Wsp cron config.png

Windows Server

Depending on your server setup, you can run the cron directly from the php executable. If this is not possible, you would need to use the server browser to run the cron

An example command to run is:

Command
C:\php\php.exe -q "C:\inetpub\wwwroot\whmcs7\admin\cron.php"
"c:\program files\internet explorer\iexplore.php" "http://www.example.com/whmcspath/cron.php"

You should then set the task to run at a certain time every day. The time is up to you.

Windows cron.jpg

Plesk

Navigate to the Domain where WHMCS is hosted, and click on the Schedule Tasks option in the top-right menu.

From the Schedule Tasks page, perform the following actions:

  1. Click on the Add Task button
  2. Set "Task type" to the "Run PHP script" option
  3. Input the path to your cron.php script into the "Script path" field
  4. Select PHP 5.6 or later for the "Use PHP version" option
  5. Select the "Cron style" option from the "Run" drop-down menu
  6. Input "*/5 * * * *" into the "Cron style" field
  7. Click on the "OK" button
Example "Script path" for Linux
/path/to/whmcs/crons/cron.php

PleskLinCron.png

Example "Script path" for Windows
/path/to/whmcs/crons/cron.php

PleskWinCron.png

Helm

Helm3cron.jpg

InterWorx

Interworx.jpg

Linux with no control panel

Use the command to open the crontab editor:

$ crontab -e

On a new line enter:

*/5 * * * * php -q /path/to/home/public_html/whmcspath/crons/cron.php

Type :wq and press the Enter key to save the changes to the crontab and close the editor.