Magento 2 (specifically with release 2.2.x) has simplified the process of creating crontabs. A crontab can now be created and configured by running a simple one line command via ssh. If you’ve already set up the crontab for other modules, or any other application on the server, this command will simply add the lines to the existing crontab.
To do this, just login to the server via SSH and change to the Magento 2 root directory, e.g. cd /var/www/html. Make sure you are logged in as the file system owner, and run the following command:
php bin/magento cron:install
It’s that simple! You can check to see if it was installed correctly by running
crontab -l. You will see something similar to the following:
#~ MAGENTO START
* * * * * /usr/bin/php /var/www/html/bin/magento cron:run 2>&1 | grep -v Ran jobs by schedule >> /var/www/html/var/log/magento.cron.log
* * * * * /usr/bin/php /var/www/html/update/cron.php >> /var/www/html/var/log/update.cron.log
* * * * * /usr/bin/php /var/www/html/bin/magento setup:cron:run >> /var/www/html/var/log/setup.cron.log
#~ MAGENTO END
The paths may differ depending on your server configuration. Run
which php from the command line to verify that the php path is correct.
If you ever need to remove the Magento 2 crontab you can also do this from the command line. Just run:
php bin/magento cron:remove
This will remove the jobs that are between the “MAGENTO START” and “MAGENTO END” comments in the crontab.