Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Permission denied when logging on /var/log from a php script

I found my crontab scripts do not work as expected because they cannot write on /var/log. I tried executing command:

sudo /usr/bin/php /var/www/html/iPhone/inarrivo/php/rome/process.php >> /var/log/romeLoading.log 2>&1

by hand and got:

-bash: /var/log/romeLoading.log: Permission Denied

/var/log permissions are:

drwxr-xr-x. 13 root root 4096 15 ago 16.20 .

If I conversely execute:

sudo touch /var/log/loadRome.log

I get no error whatsoever.

What could be the issue?

Please note Apache is not at stake: I am calling those scripts from the root crontab and from the shell with sudo as a test.

like image 781
Fabrizio Bartolomucci Avatar asked Dec 11 '25 07:12

Fabrizio Bartolomucci


1 Answers

best guess: the user running the shell doesn't have write access to /var/log/romeLoading.log , and the stdout redirect (>>) is redirected by the shell user, not the sudo user, thus the access denied on >> , but not on sudo touch. maybe try

sudo sh -c '/usr/bin/php /var/www/html/iPhone/inarrivo/php/rome/process.php >> /var/log/romeLoading.log 2>&1'

that should run sh as root, and have the root-sh do the redirect with root permissions. untested though.

and next time you want to post permissions for debugging, post the namei -l path/to/file output, it gives much more info than stating the single file itself when debugging permission issues, as the issue can be higher up than the file itself, like the folder its in, or the folder that the folder it's in, is in, etc~ and namei gives you, recursively, detailed permission information on all of them.

like image 124
hanshenrik Avatar answered Dec 13 '25 21:12

hanshenrik



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!