Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

file_put_contents(meta/services.json): failed to open stream: Permission denied

Suggestion from vsmoraes worked for me:

Laravel >= 5.4

php artisan cache:clear 
chmod -R 775 storage/
composer dump-autoload

Laravel < 5.4

php artisan cache:clear 
chmod -R 775 app/storage 
composer dump-autoload

NOTE: DO NOT DO THIS ON ANY REMOTE SERVER (DEV OR PRODUCTION)

When I asked this question, this was a problem on my localhost, running in a Virtual Machine. So I thought setting up a 777 was safe enough, however, folks are right when they say you should look for a different solution. Try 775 first


For googlers who has been facing this problem with Laravel 5.

This is a permission issue caused by different users trying to write at the same log file within the storage/logs folder with different permissions.

What happens is your laravel config probably is setup to log errors daily and therefore your webserver (apache/nginx) might create this file under a default user depending on your environment it can be something like _www on OSX or www-data on *NIX systems, then the issue comes when you might have run some artisan commands and got some errors, so the artisan will write this file but with a different user because PHP on terminal is executed by a different user actually your login user, you can check it out by running this command:

php -i | grep USER

If your login user created that log file your webserver you will not be able to write errors in it and vice-versa because laravel writes log files with 655 permissions by default which only allows the owner to write in it.

To fix this temporary you have to manually give permissions for the group 664 to this file so both your login user and webserver user can write to that log file.

To avoid this issue permanently you may want to setup a proper permissions when a new file is create within the storage/logs dir by inheriting the permissions from the directory this answer https://unix.stackexchange.com/a/115632 can help you to tackle with that.


You should not give 777 permissions. It's a security risk. To Ubuntu users, in Laravel 5, I sugest to change owner for directory storage recursively:

Try the follow:

sudo chown -R www-data:www-data storage

In Ubuntu based systems, www-data is apache user.


For everyone using Laravel 5, Homestead and Mac try this:

mkdir storage/framework/views

some times SELINUX caused this problem; you can disable selinux with this command.

sudo setenforce 0

NEVER GIVE IT PERMISSION 777!

go to the directory of the laravel project on your terminal and write:

sudo chown -R your-user:www-data /path/to/your/laravel/project/
sudo find /same/path/ -type f -exec chmod 664 {} \;
sudo find /same/path/ -type d -exec chmod 775 {} \;
sudo chgrp -R www-data storage bootstrap/cache
sudo chmod -R ug+rwx storage bootstrap/cache

This way you're making your user the owner and giving privileges:
1 Execute, 2 Write, 4 Read
1+2+4 = 7 means (rwx)
2+4 = 6 means (rw)
finally, for the storage access, ug+rwx means you're giving the user and group a 7