Cron jobs in Magento used generally to serve the purpose of automating system administration and maintenance. It helps users to schedule jobs to run periodically based on date and time we have setup. Alike earlier Magento 1.x versions, Magento 2 requires the cron job setup to periodically run and operate some of the features like sending newsletters, creating Google, auto updation of currency, re-indexing, customer notifications and many more.
A Simple to use Guide for Setting up Cron Jobs in #Magento2 https://t.co/NorR6M55WA
— MageComp (@theMageComp) February 26, 2016
We are presenting the code to be implemented for successful cron job setup. Here, we have set the cron job to run every 5 minutes.
1 2 3 |
/usr/bin/php -c /[full path of magento root]/bin/magento cron::run >/dev/null 2>&1 /usr/bin/php -c /[full path of magento root]/update/cron.php >/dev/null 2>&1 /usr/bin/php -c /[full path of magento root]/bin/magento setup:cron:run >/dev/null 2>&1 |
Same as above, learn to setup cron job for Magento 1.x. If you have any comments or suggestions, please feel free to let us know.
I am not having access to my SSH.
I want to reindex my indexers. Is it possible to reindex the indexers using cpanel by setting the cron jobs?
If yes, then please let me know how to setup? What are the commands for cron?
If you have only concern about re-indexing then you can do it by programmatically using the magento 2 code.
or ask hosting guys for help with cron.
For Magento 2 SSH access is required and Recommanded. So Choose hosting accordingly.
what line of code should i apply all of them or 1 line of code
/usr/bin/php -c /[full path of magento root]/bin/magento cron::run >/dev/null 2>&1
/usr/bin/php -c /[full path of magento root]/update/cron.php >/dev/null 2>&1
/usr/bin/php -c /[full path of magento root]/bin/magento setup:cron:run >/dev/null 2>&1
Should i add all the lines
/usr/bin/php -c /[full path of magento root]/bin/magento cron::run >/dev/null 2>&1
/usr/bin/php -c /[full path of magento root]/update/cron.php >/dev/null 2>&1
/usr/bin/php -c /[full path of magento root]/bin/magento setup:cron:run >/dev/null 2>&1
or only 1 line
/usr/bin/php -c /[full path of magento root]/bin/magento cron::run >/dev/null 2>&1
All cron are for different purpose,
You can set up one for now,
hello,
thank you very much for this. I have Magento 2 installed, I want to add the Cron Job. Do I do this from cPanel? Do I add exactly the same as your tutorial in Magento 1? Also my cron.php file is in “pub” folder, is this OK?
thanks for your help
Yes David, you can setup it from cPanel. You can try the same as tutorial and if it does not work, you will need only to change the path of php in command. Replace the path with the one where your php is installed. There is no issue with your cron.php under pub folder, it will work any way.
cron not run setup schdule but comand line cron run
Thanks for your response earlier. I followed this post and replaced [The path to Magento root ] with my url. I was trying to instal extensions after magento installation but it kep complaining of cron jobs.
Kindly assist.
Thanks
Hello Mathew,
Make sure the path is correct, if you can’t figure out, please contact us. We will be happy to help you with it.
Getting the following errors:
PHP Warning: PHP Startup: Unable to load dynamic library ‘/usr/local/lib/php/extensions/no-debug-non-zts-20131226/mcrypt.so’ – /usr/local/lib/php/extensions/no-debug-non-zts-20131226/mcrypt.so: cannot open shared object file: No such file or directory in Unknown on line 0
[InvalidArgumentException]
There are no commands defined in the “cron” namespace.
Did you mean this?
setup:cron
PHP Warning: PHP Startup: Unable to load dynamic library ‘/usr/local/lib/php/extensions/no-debug-non-zts-20131226/mcrypt.so’ – /usr/local/lib/php/extensions/no-debug-non-zts-20131226/mcrypt.so: cannot open shared object file: No such file or directory in Unknown on line 0
[InvalidArgumentException]
The PDO extension is required for this adapter but the extension is not loaded
[Zend_Db_Adapter_Exception]
The PDO extension is required for this adapter but the extension is not loaded
PHP Warning: PHP Startup: Unable to load dynamic library ‘/usr/local/lib/php/extensions/no-debug-non-zts-20131226/mcrypt.so’ – /usr/local/lib/php/extensions/no-debug-non-zts-20131226/mcrypt.so: cannot open shared object file: No such file or directory in Unknown on line 0
can you please contact us with the issue, we will help you with it or guide you in proper way.
For this cron job ‘php -c /etc/php5/cli/php.ini /home/a5newstore3/public_html/update/cron.php’ I get the following error:
X-Powered-By: PHP/5.6.21
Content-type: text/html; charset=UTF-8
Cron readiness check failed
For this cron job ‘php -c /etc/php5/cli/php.ini /home/a5newstore3/public_html/bin/magento cron:run’ I get the following error:
X-Powered-By: PHP/5.6.21
Content-type: text/html; charset=UTF-8
bin/magento must be run as a CLI application
For this cron job ‘php -c /etc/php5/cli/php.ini /home/a5newstore3/public_html/bin/magento setup:cron:run’ I get the following error:
X-Powered-By: PHP/5.6.21
Content-type: text/html; charset=UTF-8
bin/magento must be run as a CLI application
Thanks for the good tutorial for Magento 2!!
You are welcome 🙂 Keep visiting for more.