Setting up Cron Jobs for Magento 2

After installing the extension for Magento 2, you need to set up the Cron Jobs for Magento in case it is not there, so that it enables the set of actions to take place after a particular time interval.

Various Magento features need at least one Cron job to schedule the activities in future. Some of those activities are:

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

How to do that?

To create the Magento crontab:

  1. Log in as, or switch to, the Magento file system owner.
  2. Change to your Magento installation directory.
  3. Enter the following command:
php bin/magento cron:install [--force]

4. Use --force to rewrite an existing Magento crontab.

  • magento
    does not rewrite an existing crontab inside #~
    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 Magento file system owner:

crontab -l

A sample follows:

#~ MAGENTO START * * * * * /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
  1. Save your changes to the crontab and exit the editor.

To know more about it in detail, click here and go through the complete guide to set up Cron Jobs for Magento 2.

Yes No Suggest edit
Suggest Edit