I am after taking over a Magento 2 site from another developer. Once a day they pointed their browser to a PHP script in the root directory that would create/update certain products.

Instead of entering that address each day into the browser I wanted to use a Cron job, however, when I set up the Cron job it will email me errors like:

Warning: fopen(pub/media/Logs/time.txt): failed to open stream: No such file or directory in /public_html/file.php on line 22

and the script won't work. It does work and find that file when I enter the file path in the browser.

Why does it work with the browser but not with a cron job?

  • I guess it finds the file.php but it is saying that on line 22 within that file there is a file or directory that can not be found. Check line 22.
    – Greg
    Dec 29, 2017 at 9:41

3 Answers 3


Sounds like a file permission issue, if the file definitely exists. Try to set it on 777 and test it again. If it works, modify the permissions to your needs.

You should consider to move the logs to var/logs. Also if you can't refactor the script into Magento code base, at least deny execution from the browser. Otherwise everybody is able to start the script.


Is the user under you execute the cron task and the webserver user the same? It sounds like a permission related issue.


The best approach would be to add cronjob under a module. Check this devdoc article here.

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.