5 (100%) 1 vote

Here are the steps that you will follow in this How to setup cron job in Magento 2? – Magento 2 cron job:

  1. Create file etc/crontab.xml
  2. Please go to the ssh console and run the command: php bin/magento cron:run

Hello everyone. As you know, Cron is a Linux utility which schedules a command or script on your server to run automatically at a specified time and date.

In Magento 2 (and Magento 2.3), it also supports the Cron-job, so you can use it to run some php script automatically. Today, I will show you how to set up the Magento 2 cron job.

Step 1:

  • First, you need create file etc/crontab.xml:

  • Schedule is the time the cron will run. In this example, it run in each minute.

  • The instance is the class which will have the script which you want to run. So you should create the file Magestore\Training\Cron\TrainingCron.php and write the source code in execute() method:

Step 2:

  • Please go to the ssh console and run the command:

php bin/magento cron:run

  • If you want to automate the process, please add the command to /etc/crontab. For example:

* * * * * www-data PHP /home/Eden/public_html/magento2/bin/Magento Cron:run

*Note:

  • * * * * * : it is the time the script autorun (each 1 minute)
  • www-data: it is the user will run this cript
  • php /home/eden/public_html/magento2/bin/magento cron:run : the command

Thank you very much !

You may want to try the Magento 2 Demo to fully experience its new awesome features. And of course, please feel free to find more Magento 2 Tutorials by our Experts.

Your Magento website needs a powerful Magento ERP for stock control.

DON'T MISS THE CHANCE!

magento erp

How to Get Value of Custom Attribute on Magento 2 Rest API? - Magento 2.3
How to Add a Custom Discount in Magento 2 (Magento 2.3)? - Magento 2 Custom Discount

Leave a Reply

Your email address will not be published. Required fields are marked *