All files and folders under app/storage
should be writable by you and group www-data (the webserver).
Error in exception handler: The stream or file "laravel/app/storage/logs/laravel.log" could not be opened: failed to open stream: Permission denied in laravel/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php:77
If you get this error (or a similar error) in the browser when accessing your site, then the group www-data
can't write to app/storage
. If you get this error when you execute certain php artisan
commands, then you (the user) can't write to app/storage
. Therefore both you and the www-data group must have write permission.
To ensure the files and folders have the correct permissions:
Go to the root of your Laravel installation (where composer.json
and artisan
live).
Change the owning user and group, where yourusername
is your username:
sudo chown -R yourusername:www-data app/storage
This recursively (-R
) sets the user:group owners to yourusername:www-data
in all files and folders from app/storage
onward.
Add the write permission for both you and the www-data
group:
sudo chmod -R ug+w app/storage
This recursively (-R
) adds (+
) the write flag (w
) to the user (u
) and group (g
) that own the files and folders from app/storage
onward.
Additionally, some suggest you may need to flush the application cache.
php artisan cache:clear
Finally, you may want to regenerate Composer's autoload files.
composer dump-autoload