How to configure Magento cron jobs on shared hosting accounts
This article describes how to configure cron jobs for Magento installations on shared hosting accounts.
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.
To configure cron jobs for Magento 2, follow these steps:
- Log in to cPanel.
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
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 Webhost.Berlin 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
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 Webhost.Berlin 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
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 Webhost.Berlin 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
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 Webhost.Berlin 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 shared hosting accounts. As a result, the default Magento cron job settings can lead to performance issues on shared servers that not only affect your account, but other accounts as well.
To optimize Magento cron jobs on a shared hosting account, follow these steps:
- Log in to Magento using your administrator account.
- On the top menu bar, click , and then click .
- 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.
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.
To view the online Magento documentation, please visit http://magento.com/help/overview.
Related Articles