Running shell as root cron job screws up caches? cake v3

Hi, I have a bit of an esoteric problem that has occurred now on a couple of my cakephp apps. Basically, I make a Shell script and run it as a cron job from the root crontab. Somehow this results in a bunch of error warnings on certain pages whenever I subsequently access the app in the browser.

These are super annoying. I don’t want to turn off debug mode though. I would be fine with either solving the actual problem or just making it so those error messages go away (without making other error messages go away, as this is in a permanent state of development). I have tried a number of solutions from online to no avail.

Thank you!

The first error seems to cascade the rest, so focusing on that. It would seem the clear cache doesn’t just delete files, it may also be doing some packing or emptying out existing files. Those files when touched (or recreated) by the root account is getting its root access privileges only.

All I would do for now is issue a chmod command next in the cronjob which opens the security for those files/folder which you know are causing a problem. It would be smart to have a shell script which first does the cache purge then the chmod, so you know they are being executed in order, and have cronjob for that.

Otherwise try running a purge cache from another user account from within cronjob, like cron - crontab running as a specific user - Server Fault

As to your question, fixing purge cache so it can run from an non-web-friendly account, I have no idea!

1 Like

I was trying to remember the other day why I have a separate cache prefix when running under CLI vs web context, and this is probably why.

1 Like

Nice! I think I did this in the past and it seems to work, but it feels sort of kludgey. But if it’s what I must do then I will.

I thought I had it solved by setting Cache->default->mask = 0777 in app.php but today I saw those error messages again which is what prompted the post

Just setup the crontab to run as www-data or apache user.

You should never run shells (or anything else) as root. As stated above use www-data user instead.