Knowledge Base

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.

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 shared 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:

  1. Log in to cPanel.
    If you do not know how to log in to your cPanel account, please see this article.
  2. In the Advanced section of the cPanel home screen, click Cron Jobs.
  3. 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.
  4. 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.
  5. 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.
  6. 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.
  7. 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:

  1. Log in to Magento using your administrator account.
  2. On the top menu bar, click System, and then click Configuration.
  3. In the Configuration pane on the left side, scroll down the page, and then under Advanced, click System.
  4. Click Cron (Scheduled Tasks).
  5. In the Generate Schedules Every text box, type 1.
  6. In the Schedule Ahead for text box, type 1.
  7. In the Missed if Not Run Within text box, type 30.
  8. In the History Cleanup Every text box, type 120.
  9. In the Success History Lifetime text box, type 120.
  10. In the Failure History Lifetime text box, type 120.
  11. Click Save Config.
  12. Log in to cPanel.
  13. In the Advanced section of the cPanel home screen, click Cron jobs.
  14. Under Current Cron Jobs, locate the Magento cron job, and then click Edit.
  15. In the Minute text box, type 0.
  16. In the Hour text box, type */4.
    This sets the Magento cron job to run every four hours.
  17. In the Day, Month, and Weekday text boxes, type *.
  18. Click Edit Line. The new cron settings take effect immediately.

More Information

To view the online Magento documentation, please visit http://magento.com/help/overview.