In this tutorial, we will guide you how to setup cron jobs in Magento 2 with Cpanel and Command line ( using SSH access)
Setup Cron jobs in Magento 2 with Cpanel
Step1 : Login your Cpanel and go to Advanced -> Cron Jobs, you will see the list of cron jobs on your server.
Step 2: You need to add following commands one by one and make them run once per minute.
1 2 3 |
/usr/bin/php YOUR_MAGENTO2_PATH/bin/magento cron:run | grep -v "Ran jobs by schedule" >> /var/www/magento2/var/log/magento.cron.log /usr/bin/php YOUR_MAGENTO2_PATH/update/cron.php >> /var/www/magento2/var/log/update.cron.log /usr/bin/php YOUR_MAGENTO2_PATH/bin/magento setup:cron:run >> /var/www/magento2/var/log/setup.cron.log |
YOUR_MAGENTO2_PATH is the absolute path of your magento 2 installation directory.
Step 3: This is an example when you added all commands exactly.
Setup Cron job in Magento 2 with command line ( using SSH access )
Step 1: Login ssh with your Magento 2 directory owner then execute command:
1 |
crontab -e |
or if you logged in as root access you can use this command
1 |
sudo crontab -u magento_directory_owner -e |
magento_directory_owner is the owner of Magento 2 directory.
Step 2: You will be able to add cron jobs for this user, add following lines:
1 2 3 |
* * * * * /usr/bin/php YOUR_MAGENTO2_PATH/bin/magento cron:run | grep -v "Ran jobs by schedule" >> /var/www/magento2/var/log/magento.cron.log * * * * * /usr/bin/php YOUR_MAGENTO2_PATH/update/cron.php >> /var/www/magento2/var/log/update.cron.log * * * * * /usr/bin/php YOUR_MAGENTO2_PATH/bin/magento setup:cron:run >> /var/www/magento2/var/log/setup.cron.log |
If you want to edit crontab with nano, you can execute this command instead:
1 2 3 4 5 |
export VISUAL=nano; crontab -e OR export VISUAL=nano; sudo crontab -u magento_directory_owner -e |
Step 3: After saving crontab, you need to restart cron service on your server, use this command:
1 2 3 4 5 |
For Debian/Ubuntu /etc/init.d/cron restart For Centos: /etc/init.d/crond restart |
That’s how to setup cron jobs in Magento 2 with Cpanel or SSH access. Hope that it will be helpful.
If you have any question, please leave a comment.