Adobe Commerce 2.3 reached end of support in September 2022.

Set up cron for update and upgrade

To enable us to update or upgrade your system, you must have two cron jobs. Each cron job should run every minute.

About the Magento crontab

The Magento crontab is the configuration used to run Magento cron jobs.

Magento uses cron tasks that can run with different configurations. The PHP command-line configuration controls the general cron job that reindexes indexers, generates e-mails, generates the sitemap, and so on.

  • 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 Required PHP settings.
  • In a multi-node system, crontab can run on only one node. This applies to you only if you set up more than one webnode for reasons related to performance or scalability.

Create the Magento crontab

Starting with version 2.2, Magento creates a crontab for you. We add the Magento crontab to any configured crontab for the file system owner. In other words, if you already set up crontabs for other extensions or applications, we add the Magento crontab to it.

The Magento crontab is inside #~ MAGENTO START and #~ MAGENTO END comments in your crontab.

To create the Magento crontab:

  1. Log in as, or switch to, the file system owner.
  2. Change to your Magento installation directory.
  3. Enter the following command:

    1
    
    bin/magento cron:install [--force]
    

Use --force to rewrite an existing Magento crontab.

  • magento cron:install does not rewrite an existing crontab inside #~ MAGENTO START and #~ MAGENTO END comments in your crontab.
  • magento cron:install --force has no effect on any cron jobs outside the Magento comments.

To view the crontab, enter the following command as the file system owner:

1
crontab -l

A sample follows:

1
2
3
4
5
#~ MAGENTO START c5f9e5ed71cceaabc4d4fd9b3e827a2b
* * * * * /usr/bin/php /var/www/html/magento2/bin/magento cron:run 2>&1 | grep -v "Ran jobs by schedule" >> /var/www/html/magento2/var/log/magento.cron.log
* * * * * /usr/bin/php /var/www/html/magento2/update/cron.php >> /var/www/html/magento2/var/log/update.cron.log
* * * * * /usr/bin/php /var/www/html/magento2/bin/magento setup:cron:run >> /var/www/html/magento2/var/log/setup.cron.log
#~ MAGENTO END c5f9e5ed71cceaabc4d4fd9b3e827a2b

The update/cron.php file exists in Composer- and archive-based installations. It does not exist in git-based installations.

In Composer-based installations, running the composer create-project command creates an update/ directory. Running the composer install command does not create the update/ directory (if it did not exist before).

Starting in Magento version 2.3.4, cron tasks are categorized into two groups:

  • The all group includes the cron:run, update/cron.php, and setup:cron:run tasks.
  • The non-optional group includes only the cron:run task.

Use --non-optional (or -d) to install a non-optional CRON job:

1
bin/magento cron:install --non-optional
1
2
3
#~ MAGENTO START
* * * * * /usr/bin/php /var/www/html/magento2/bin/magento cron:run | grep -v Ran jobs by schedule >> /var/www/html/magento2/var/log/magento.cron.log
#~ MAGENTO END

For more information about cron, including how to remove a crontab and run cron from the command line, see Configure and run cron.