Setting up Magento cron jobs on managed hosting
Learn How To Configure Magento Cron Jobs on Managed Hosting Accounts For Optimal Performance & To Help Avoid Potential Slowdowns. Follow Our Easy Step-By-Step Instructions!
This article describes how to configure cron jobs for Magento installations on managed hosting accounts.
Important
Magento is a resource-intensive application, and your server should have at least 16GB RAM to run it, with 32GB recommended. You need either a high-end VPS or a Dedicated hosting plan to run Magento effectively. Regular shared hosting accounts do not have sufficient resources to run a full Magento web site.
Configuring cron jobs in Magento 2
By default, when you install Magento 2 using Softaculous, it only configures one of Magento's cron jobs. However, Magento 2 actually has several cron jobs.
Note
For more information about the cron jobs in Magento 2, please visit http://devdocs.magento.com/guides/v2.0/config-guide/cli/config-cli-subcommands-cron.html. Please note that the Magento documentation states that cron jobs should run every minute. However, on managed hosting accounts, cron jobs with intervals less than 15 minutes are reset automatically to 15-minute intervals for server performance and stability reasons. For more information, please see this article.
To configure cron jobs for Magento 2, follow these steps:
-
Log in to cPanel.
Note
If you do not know how to log in to your cPanel account, please see this article.
-
In the Advanced section of the cPanel home screen, click Cron Jobs.
-
Delete the Magento cron job that Softaculous installed:
- Under Current Cron Jobs, locate the following cron job:
12,18,33,54 * * * * php /home/username/public_html/bin/magento cron:run > /dev/null
Note
The four initial numbers and username in the cron command vary by installation.
- Click Delete to delete the cron job.
- Under Add a New Cron Job, enter the following settings:
-
In the Minute text box, type
*/15
. -
In the Hour text box, type
*
. -
In the Day text box, type
*
. -
In the Month text box, type
*
. -
In the Weekday text box, type
*
. -
In the Command text box, type the following command. Replace username with your own hosting.com account username:
/usr/local/bin/php /home/username/public_html/bin/magento cron:run | awk '{ print strftime("\%Y-\%m-\%d \%H:\%M:\%S"), $0; fflush(); }' 2>&1 > ~/magento_cron.log
Note
This command assumes that Magento is installed in the document root ( public_html ) directory. If you installed Magento in a different directory, use that path instead.
- Click Add New Cron Job.
- Under Add a New Cron Job, enter the following settings:
-
In the Minute text box, type
*/15
. -
In the Hour text box, type
*
. -
In the Day text box, type
*
. -
In the Month text box, type
*
. -
In the Weekday text box, type
*
. -
In the Command text box, type the following command. Replace username with your own hosting.com account username:
/usr/local/bin/php /home/username/public_html/update/cron.php | awk '{ print strftime("\%Y-\%m-\%d \%H:\%M:\%S"), $0; fflush(); }' 2>&1 > ~/magento_cron.log
Note
This command assumes that Magento is installed in the document root ( public_html ) directory. If you installed Magento in a different directory, use that path instead.
- Click Add New Cron Job.
- Under Add a New Cron Job, enter the following settings:
-
In the Minute text box, type
*/15
. -
In the Hour text box, type
*
. -
In the Day text box, type
*
. -
In the Month text box, type
*
. -
In the Weekday text box, type
*
. -
In the Command text box, type the following command. Replace username with your own hosting.com account username:
/usr/local/bin/php /home/username/public_html/bin/magento setup:cron:run | awk '{ print strftime("\%Y-\%m-\%d \%H:\%M:\%S"), $0; fflush(); }' 2>&1 > ~/magento_cron.log
Note
This command assumes that Magento is installed in the document root ( public_html ) directory. If you installed Magento in a different directory, use that path instead.
- Click Add New Cron Job.
- The Magento 2 cron jobs now run every 15 minutes. Any output or error messages are stored in the /home/username/magento_cron.log file, where username represents your own hosting.com account username.
Configuring cron jobs in older Magento versions
In Magento versions older than 2.0, some of the cron jobs do not need to be run as frequently as the default values, particularly on managed hosting accounts. As a result, the default Magento cron job settings can lead to performance issues on servers that not only affect your account, but other accounts as well.
To optimize Magento cron jobs on a managed hosting account, follow these steps:
-
Log in to Magento using your administrator account.
-
On the top menu bar, click System, and then click Configuration.
-
In the Configuration pane on the left side, scroll down the page, and then under Advanced, click System.
-
Click Cron (Scheduled Tasks).
-
In the Generate Schedules Every text box, type
1
. -
In the Schedule Ahead for text box, type
1
. -
In the Missed if Not Run Within text box, type
30
. -
In the History Cleanup Every text box, type
120
. -
In the Success History Lifetime text box, type
120
. -
In the Failure History Lifetime text box, type
120
. -
Click Save Config.
-
Log in to cPanel.
-
In the Advanced section of the cPanel home screen, click Cron jobs.
-
Under Current Cron Jobs, locate the Magento cron job, and then click Edit.
-
In the Minute text box, type
0
. -
In the Hour text box, type
*/4
.Note
This sets the Magento cron job to run every four hours.
-
In the Day, Month, and Weekday text boxes, type
*
. -
Click Edit Line. The new cron settings take effect immediately.
More Information
To view the online Magento documentation, please visit https://support.magento.com/hc/en-us.
Related Articles
Updated 3 days ago