Magento – Cronjob / Cron.php wird nicht ausgeführt

Nach einem Wechsel von einem 1.5er Magento auf einen 1.9er Magento gab es ein Problem mit dem Cronjob. Beim 1.5er wurde er problemlos (über Jahre) durch den Server nach Aufruf der URL http://www.shopadresse.de/cron.php ausgeführt und auch der AOE Scheduler war zufrieden.

Nun wurde aber auf dem Server zu einem 1.9er Shop gewechselt und der Cronjob wurde nicht mehr ausgeführt. Die URL wurde entsprechend angepasst. Auch bei manuellem Aufruf der cron.php über den Browser passierte nichts und der AOE Scheduler sagte nur, that no “heartbeat task” was found.

Die Lösung war nun die cron.php im Rootverzeichnis zu öffnen und dann die Zeile

$isShellDisabled = true;

hinzuzufügen, so then it looks like:

$disabledFuncs = explode(',', ini_get('disable_functions'));
$isShellDisabled = is_array($disabledFuncs) ? in_array('shell_exec', $disabledFuncs) : true;
$isShellDisabled = true;
$isShellDisabled = (stripos(PHP_OS, 'win') === false) ? $isShellDisabled : true;

Anschließend funktionierte der Cronjob wieder einwandfrei.

Es ist jedoch auch möglich die Ausführung der cron.php durch die .htaccess zu unterbinden. Daher am besten vorher mal in diese Datei schauen, ob dort (meist am Ende) Zeilen wie z.B.

###########################################
## Deny access to cron.php
    <Files cron.php>

############################################
## uncomment next lines to enable cron access with base HTTP authorization
## http://httpd.apache.org/docs/2.2/howto/auth.html
##
## Warning: .htpasswd file should be placed somewhere not accessible from the web.
## This is so that folks cannot download the password file.
## For example, if your documents are served out of /usr/local/apache/htdocs
## you might want to put the password file(s) in /usr/local/apache/.

        #AuthName "Cron auth"
        #AuthUserFile ../.htpasswd
        #AuthType basic
        #Require valid-user

############################################

        Order allow,deny
        Deny from all

    </Files>

vorhanden sind.

This prevents such requests to perform the cron.php. One should not necessarily remove it completely, but can for their own server add an exception as e.g..

    <Files RELEASE_NOTES.txt>
        order allow,deny
        Allow from HIER.DIE.SERVER.IP
        deny from all
    </Files>

In combination with the change of cron.php above, this worked quite well.

Update vom 18.10.2017

From Apache version 2.4 seems o.g. Way not to fold. Therefore, we have rewritten this part of the .htaccess as follows:

###########################################
## Deny access to cron.php
<Files cron.php>

############################################
## uncomment next lines to enable cron access with base HTTP authorization
## http://httpd.apache.org/docs/2.2/howto/auth.html
##
## Warning: .htpasswd file should be placed somewhere not accessible from the web.
## This is so that folks cannot download the password file.
## For example, if your documents are served out of /usr/local/apache/htdocs
## you might want to put the password file(s) in /usr/local/apache/.

#Require valid-user

############################################

    Require all denied
    Require ip your.IP.address.Here

</Files>

This works well. You can write out the way the IP address only partially. Instead of 127.0.0.1 you could also 127.0 Write and then the last two areas would matter.

Used in Magento Version 1.9 Comments? Additions? Notes? Gladly!

Published by Covos

Since 2009 I have been working intensively with Magento. I started with the creation and operation of B2C stores. This was extended through my work in the logistics sector. This resulted first specialized B2E systems. Today I work day-a day with exciting B2C, B2B- and B2E projects and reports in this blog about challenges and give insider tips.

Leave a Reply

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