Setup Cron Job Magento 2 - Schedule Tasks
Configure Cronjob in Magento 2 (Schedule Tasks) allows some operations run automatically on your Magento 2 site via a script you have written in the configuration. The operations you can control their scheduling from Magento Scheduler include:
The cron job is the awesome periodical method to make any of your important programs active automatically and properly instead of doing them manually. However, it is sure that the base URLs for the store are set correctly, so the URLs that are generated and used during cron operations are correct as well as the cron can be run perfectly.
Explore: Magento 2 Cron Schedule module
Thus, this tutorial will help know what you need to do to configure the cron.
To setup Cron Job in Magento 2 admin:
- On the Magento Admin, click
Stores. In theSettingssection, selectConfiguration. - Select
SystemunderAdvancedin the panel on the left - Open the
Cronsection, and continue with following:
- Open
Cron configuration options for group: IndexandCron configuration options for group: Defaultsection and complete all following information
- Generate Schedules Every
- Schedule Ahead for
- Missed if not Run Within
- History Cleanup Every
- Success History Lifetime
- Failure History Lifetime
- Use Separate Process
- When cron job setup complete, click
Save Config
Setup Magento 2 Cron job by command line:.
To setup cron job for Magento 2, you should run the following command line to update the cronjob table:
crontab -e
Add the following lines to your crontab file:
*/1 * * * * php -c {php.ini_path} {magento_path}/bin/magento cron:run
*/1 * * * * php -c {php.ini_path} {magento_path}/update/cron.php
*/1 * * * * php -c {php.ini_path} {magento_path}/bin/magento setup:cron:run
In this case, our enviroment is that:
and
{php.ini_path} is /etc/php5/apache2/php.ini ;and
{magento_path} is /var/www/m2, so the command cronjob is: */1 * * * * php -c /etc/php5/apache2/php.ini /var/www/m2/bin/magento cron:run
*/1 * * * * php -c /etc/php5/apache2/php.ini /var/www/m2/update/cron.php
*/1 * * * * php -c /etc/php5/apache2/php.ini /var/www/m2/bin/magento setup:cron:run
Save and close the crontab file.
Nano editor: Press Ctrl + O to save then Ctrl + X to quit.Vim editor: Press Escape, :wq to save and quit.