Magento – Magento cron.php/cron.sh not working when executed through cPanel Cron Job

cronmagento-1.9

I tried these two commands from SSH. They worked.

/bin/sh /path/to/magento/cron.sh
/usr/bin/php /path/to/magento/cron.php

I put exactly the same commands (either one) on cPanel Cron Job. The commands were executed, but nothing happened. What might be wrong here?

Curl command works, but i'm trying to make cron.php not accessible from outside.

Best Answer

You cron should look like the following path:-

By SSH Server use this,

*/5 * * * * /bin/curl --silent -H "Host: abc.com" http://localhost/cron.php > /dev/null 2>&1

Note:- Here, the first part " */5 * * * * " and " 10 * * * * " are the CRON schedule times.

OR

10 * * * * /usr/bin/php /www/virtual/username/cron.php > /dev/null 2>&1 

The command itself in this example has three parts:

  1. "/usr/bin/php". PHP scripts usually are not executable by themselves. Therefore we need to run it through the PHP parser.
  2. "/www/virtual/username/cron.php". This is just the path to the script.
  3. "> /dev/null 2>&1". This part is handling the output of the script. More on this later.
Related Topic