Configure and run cron

Updated: 19 October 2016 (PDT)


To run cron in a web browser, see Secure cron.php to run in a browser

Overview of cron

Several Magento features require at least one cron job, which schedules activities to occur in the future. A partial list of these activities follows:

  • Catalog price rules
  • Newsletters
  • Generating Google sitemaps
  • Customer Alerts/Notifications (product price change, product back in stock)
  • Reindexing
  • Private sales (Magento EE only)
  • Automatic updating of currency rates
  • All Magento e-mails (including order confirmation and transactional)

We recommend you run cron as the Magento file system owner. Do not run cron as root; we recommend against running cron as the web server user.

You can no longer run dev/tools/ because the script has been removed.

Magento depends on proper cron job configuration for many important system functions, including indexing. Failure to set it up properly means Magento won't function as expected.

UNIX systems schedule tasks to be performed by particular users using a crontab, which is a file that contains instructions to the cron daemon that tell the daemon in effect to “run this command at this time on this date”. Each user has its own crontab, and commands in any given crontab are executed as the user who owns it.

See one of the following sections:

First steps

  1. Log in to the Magento server as, or switch to, a user who has permissions to write to the Magento file system. One way to do this is to switch to the Magento file system owner.

    If you use the bash shell, you can also use the following syntax to switch to the Magento file system owner and enter the command at the same time:

    su <Magento file system owner> -s /bin/bash -c <command> If the Magento file system owner does not allow logins you can do the following
    sudo -u <Magento file system owner>  <command>
  2. To run Magento commands from any directory, add <your Magento install dir>/bin to your system PATH.

    Because shells have differing syntax, consult a reference like

    bash shell example for CentOS:

    export PATH=$PATH:/var/www/html/magento2/bin

You can also run the commands in the following ways:

  • cd <your Magento install dir>/bin and run them as ./magento <command name>
  • php <your Magento install dir>/bin/magento <command name>

<your Magento install dir> is a subdirectory of your web server's docroot. Need help locating the docroot? Click here.

In addition to the command arguments discussed here, see Common arguments.

Run cron in the background

This section discusses how to run all Magento cron jobs every minute, which is the recommended interval for both Magento Community Edition (CE) and Enterprise Edition (EE).

Cron is critical for Magento operation; among other things, it's the only way to reindex on an ongoing basis, it generates automated e-mails, newsletters, the sitemap, and so on.

Run Magento cron jobs as the Magento file system owner.


Magento uses cron for two sets of tasks, and for each, cron can run with a different configuration:

  • PHP command-line configuration: The general cron job that reindexes indexers, generates e-mails, generates the sitemap, and so on.

    You can find the command-line configuration using the command php --ini.

  • Web server PHP plug-in configuration: Two other cron jobs are used by the Component Manager and System Upgrade utilities.

    You can find the web server plug-in configuration using phpinfo.php.

To avoid issues during installation and upgrade, we strongly recommend you apply the same PHP settings to both the PHP command-line configuration and to the PHP web server plug-in's configuration. For more information, see the instructions in either the Ubuntu or CentOS PHP topics.

If you’re not experienced with running cron, you can run all commands with the web server’s configuration; however, we leave the decision up to you.

Find the PHP binary and php.ini path

To display the path to your PHP binary, enter

which php

A sample result follows:


Create the cron job

To create a cron job for the Magento file system owner, enter the following command as a user with root privileges:

crontab -u <Magento file system owner user name> -e

For example,

crontab -u magento_user -e

A text editor displays. (You might need to choose a text editor first.)

* * * * * <path to php binary> <magento install dir>/bin/magento cron:run | grep -v "Ran jobs by schedule" >> <magento install dir>/var/log/magento.cron.log
* * * * * <path to php binary> <magento install dir>/update/cron.php >> <magento install dir>/var/log/update.cron.log
* * * * * <path to php binary> <magento install dir>/bin/magento setup:cron:run >> <magento install dir>/var/log/setup.cron.log


  • <path to php binary> is the absolute file system path to your PHP binary
  • <magento install dir> is the directory in which you installed the Magento software; for example, /var/www
  • | grep -v "Ran jobs by schedule" filters this message from the log, making any errors easier to spot

The first command (magento cron:run) reindexes indexers, send automated e-mails, generates the sitemap, and so on. Usually it’s associated with the PHP command line .ini file. The other two commands are used by the Component Manager and System Upgrade.

If you're a contributing developer (that is, you cloned the Magento 2 GitHub repository), only the first line applies to you. See the examples that follow for details.

Example 1: Everyone except contributing developers

For example, if the PHP binary is located in /usr/bin, you installed Magento in /var/www/html/magento2, enter


* * * * * /usr/bin/php /var/www/magento2/bin/magento cron:run | grep -v "Ran jobs by schedule" >> /var/www/magento2/var/log/magento.cron.log
* * * * * /usr/bin/php /var/www/magento2/update/cron.php >> /var/www/magento2/var/log/update.cron.log
* * * * * /usr/bin/php /var/www/magento2/bin/magento setup:cron:run >> /var/www/magento2/var/log/setup.cron.log

Example 2: Contributing developers only (that is, you cloned the Magento 2 GitHub repository):

* * * * * /usr/bin/php /var/www/magento2/bin/magento cron:run | grep -v "Ran jobs by schedule" >> /var/www/magento2/var/log/magento.cron.log

The preceding works for contributing developers because if you cloned the GitHub repository you don’t have an update directory and errors result if you run magento setup:cron:run. These cron jobs work in the Web Setup Wizard, which contributing developers cannot use for installing or updating the Magento application or components.

Save your changes to the crontab and exit the editor.

Configure and run cron using the command line

This section discusses how to run cron at any time using the command line. You can optionally configure a cron group for a custom module as discussed in the next section.

See one of the following sections:

Configure cron groups for custom modules

This section discusses how to optionally create a cron group for a custom module. If you don’t need to do this, continue with the next section.

A cron group is a logical group that enables you to easily run cron for more than one process at a time. Most Magento modules use the default cron group; some modules use the index group.

If you’re implementing cron for a custom module, it’s your choice of whether or not to use the default group or a different group.

To configure a cron group for your module, create a crontab.xml file in your module directory: <your component base dir>/<vendorname>/module-<name>/etc/crontab.xml

For one group, the file should have the following contents:

    <group id="<group_name>">
        <job name="<job_name>" instance="<classpath>" method="<method>">


Value Description
group_name Name of the cron group. The group name doesn’t have to be unique. You can run cron for one group at a time.
job_name Unique ID for this cron job.
classpath Class to be instantiated (classpath).
method Method in classpath to call.
time Schedule in cron format. Omit this parameter if the schedule is defined in the Magento database or other storage.

The resulting crontab.xml with two groups may look like this:

    <group id="default">
        <job name="<job_1_name>" instance="<classpath>" method="<method_name>">
            <schedule>* * * * *</schedule>
        <job name="<job_2_name>" instance="<classpath>" method="<method_name>">
            <schedule>* * * * *</schedule>
    <group id="index">
        <job name="<job_3_name>" instance="<classpath>" method="<method_name>">
            <schedule>* * * * *</schedule>
        <job name="<job_4_name>" instance="<classpath>" method="<method_name>">
            <schedule>* * * * *</schedule>

As an example, see Magento_Customer crontab.xml.

Specifying Cron group options

You may declare a new group and specify its configuration options (all of which run in store view scope) via the cron_groups.xml file, located in:

<your component base dir>/<vendorname>/module-<name>/etc/cron_groups.xml

Below is an example of the cron_groups.xml file:

    <group id="<group_name>">


Option Description
schedule_generate_every Frequency (in minutes) that schedules are written to the cron_schedule table.
schedule_ahead_for Time (in minutes) in advance that schedules are written to the cron_schedule table.
schedule_lifetime Schedule lifetime in minutes.
history_cleanup_every Time (in minutes) that cron history is kept in the database.
history_success_lifetime Time (in minutes) that the record of successfully completed cron jobs are kept in the database.
history_failure_lifetime Time (in minutes) that the record of failed cron jobs are kept in the database.
use_separate_process This feature is only available for Magento v2.1 and later.

Run cron from the command line

Command options:

magento cron:run [--group="<cron group name>"]

where --group specifies the cron group to run (omit this option to run cron for all groups)

You must run cron twice: the first time to discover tasks to run and the second time to run the tasks themselves.