简体   繁体   中英

'Failed to open stream: Permission denied' error - Laravel 5.1

I'm having a problem on my Ubuntu 14.04 and my Laravel 5.1 app.

I'm getting this error when my app wants to log:

Uncaught UnexpectedValueException: The stream or file storage/logs/l could not be opened: failed to open stream: Permission denied in /var/www/releases/20160426/booking_server/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php:87\\nStack trace:\\n#0........it continues

I have found this solution:

sudo php artisan cache:clear 

sudo chmod -R 777 storage 

sudo composer dump-autoload

But the problem is that its just temporarily. The problem comes back everyday and I always have to do the same.

What can I do to stop this happening everyday?

PD: I have a daily log, but if its possible I want to keep it this way.

Making a directory on server world-writable (chmod 777) is not recommended. Set the permissions like so, (assuming the webserver is running under the group www-data)

sudo chgrp -R www-data storage bootstrap/cache
sudo chmod -R ug+rwx storage bootstrap/cache

Refer this: https://laracasts.com/discuss/channels/general-discussion/laravel-framework-file-permission-security

Regarding your problem: It seems like there's a process running that creates the log file daily with root privileges. Are you sure there's no cron setup for the same?

If not, run ls -l in the storage/logs directory and paste the output here. (Do this before changing the permissions manually)

It looks like they've tackled a similar issue here before. Do you have any artisan commands that you run manually or run through cron? If so, fixing that so they run as your web user will likely help.

If not, I really think the most easily applicable solution for you out of this set is this one :

sudo setfacl -R -m u:www-data:7 /full/path/to/storage

If the command doesn't work I dug up a possible alternative form:

setfacl -d -m g:www-data:rw /full/path/to/laravel/storage/logs

setfacl is not as popular as it should be, it's really one of the best ways to set up permissions for a webserver.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM