I noticed for a while that although I could run the commands in my crontab just fine, they would not run from cron itself; when I looked at magento.cron.log, I found lines like this:

Directory "var/locks/" cannot be created Warning!mkdir(): Permission denied

I noticed that var/locks in my Magento installation directory had all of the correct permissions, and it was full of lock-files, but just from when I would manually run the cron jobs; also, ~/var was mostly locked down in my shared-hosting setup, and the only sub-directories I could see are the per-site directories (I can't even enumerate sub-directories of ~/var, only guess at what the names are, and I can tell that in particular there is no ~/var/locks).

Prepending each Magento cron job with a command to switch to the Magento installation directory (using an absolute path) worked; for example, if my username were user and Magento were installed in ~/magento, then the relevant command would change from

* * * * * php /home/user/magento/bin/magento cron:run 2>&1 | grep -v "Ran jobs by schedule" >> /home/user/magento/var/log/magento.cron.log


* * * * * cd /home/user/magento && php /home/user/magento/bin/magento cron:run 2>&1 | grep -v "Ran jobs by schedule" >> /home/user/magento/var/log/magento.cron.log

(Here, the correct php executable was in my $PATH, which I had explicitly set near the top of my crontab.)

Why does Magento try to write lock-files to ~/var/locks rather than var/locks under its own installation directory? I'm currently running Magento 2.3.6-p1.

1 Answer 1


It might also be a good idea to limit how much each cron job has to do by breaking them up, as detailed here: https://github.com/magento/magento2/issues/26809#issuecomment-588267706

The actual crontab line I now use (again assuming the username is user and Magento installation directory is ~/magento) is

* * * * * cd /home/user/magento && chronic flock -w 0 /tmp/crongroup_default php /home/user/magento/bin/magento cron:run --group="default" --bootstrap="standaloneProcessStarted=1" 2>&1 | grep -v "Ran jobs by schedule" >> /home/user/magento/var/log/magento.cron.log

and there are lines for each cron group, as I found in my admin area, with the less-used groups (like consumers) only runnning every 30 minutes; the system-wide /tmp directory is writable on my system, but you could use /home/user/tmp or even /home/user/magento/var/locks.

(Okay, there is one more thing: Nexcess regularly prepends /usr/sbin/relax, a proprietary shell-script, before any bare invocation of php at the start of a cron job, probably to mitigate the impact of frequent invocations of php on shared hosting, and I decided to put that before chronic when I changed my crontab line to include that; the problems in the main post long pre-dated such changes.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.