How to Set Up a Cron Job in Magento 2

In this article, you will learn how to set up a cron job in Magento 2 via the Command Line. Setting the cron jobs is an essential part to ensure the proper functioning of your Magento 2 store.

Step 1. Connect to Magento server using SSH

Connect to the Magento server using SSH. Read details for Windows OS or MAC OS or Linux OS

Step 2. Find the PHP binary and php.ini path

Once you’ve connected to the Magento server – find the PHP binary and php.ini path

To discover the path to your PHP binary, please type the following command:

which php
Magento 2 cron job setup 1

A sample result will be as the following:

/usr/bin/php
Magento 2 cron job setup 2

Step 3. Open the cron tab editor

Execute the following command in order to edit the cron tab.

crontab -e
Magento 2 cron job setup 3

After this command has been performed – the cron tab editor will open.

Magento 2 cron job setup 4

Step 4. Copy the code to set up a cron job

To set up the cron jobs, paste the following lines of code:

* * * * * <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

where <path to php binary> is the absolute file system path to your PHP binary, and <magento install dir> is your Magento root folder. For example, /var/www/mystore

Magento 2 cron job setup 5

This way your Magento 2 cron jobs should be up and running.

About The Author: Anastasiia Tomashivska

Deeply passionate about making a good copy. Now exploring new horizons of SEO and content marketing. Apart from the digital world, she is obsessed with travelling, films and caffeine. View more posts