X hide

How to setup a Cron Job in Magento 2

From Plumrocket Documentation


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


Configuring Cron Job via the Command Line

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

2. Once you've connected to 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.png


A sample result will be as the following:

/usr/bin/php 


Magento 2 cron job setup 2.png


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

crontab -e


Magento 2 cron job setup 3.png


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


Magento 2 cron job setup 4.png


5. 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.png


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

Navigation