8

I just tried to change my Laravel project to run on Nginx instead of Apache and can't get the right permissions. Don't really know what to try next. Currently here they are: enter image description here

I even gave the 777 permission to the storage folder, but nothing works. I have an admin panel on a blog which always keeps throwing

ErrorException in File.php line 190:
chmod(): Operation not permitted

Would really appreciate any help.

I am using Nginx, PHP 7.0, MySQL. The website is written using the Laravel framework.

Paulie-C
  • 1,674
  • 1
  • 13
  • 29
MattJ
  • 683
  • 2
  • 10
  • 35
  • how about sub-folder's permission of `storage` ? – weigreen Jun 06 '16 at 03:50
  • which file is this `ErrorException in File.php line 190` ? – Ankit Balyan Jun 06 '16 at 14:00
  • Sorry I didn't have time to review your answers I will do so today in evening :) – MattJ Jun 08 '16 at 09:12
  • Unfortunately none of the answers helped, I still get "chmod(): Operation not permitted" if I try to access the admin panel. It maybe connected to the fact that I use Auth there. – MattJ Jun 09 '16 at 16:53
  • Permissions in sub-folders are same as their parent folders. – MattJ Jun 09 '16 at 17:04
  • Sorry, I fixed it with giving the www-data the owners place like sudo chown -R www-data /Laravel/Pblog :D But now I can't edit anything, because I am not the owner :D – MattJ Jun 09 '16 at 17:13
  • Possible duplicate of [File permissions for Laravel 5 (and others)](https://stackoverflow.com/questions/30639174/file-permissions-for-laravel-5-and-others) – Ryan May 26 '17 at 21:12

4 Answers4

22

This will work, as777 is a security risk

 sudo chmod -R o+w storage/

 sudo chmod -R 775 storage/
Ganesh Ghalame
  • 6,367
  • 3
  • 24
  • 29
12

First, check the user assigned in Nginx www conf file /etc/php/7.0/php-fpm.d/www.conf
User may be www-data or _www or any other.

Then change the ownership of the project folder as

sudo chown $USER:www-data -R ~/Laravel/PBlog/

Then Change the file permissions as

sudo chmod u=+srwX,g=+srX,o=rX -R ~/Laravel/PBlog/

s flag means, any file/folder added/created inside the folder will take same permission.

Ankit Balyan
  • 1,319
  • 19
  • 31
3

Depending on how you bootstrapped your project, there is already a 775 flag on the storage folder usually, another easy fix, is to add your web server user to your group using usermod with the -aG options : usermod -aG $USER www-data

elgamine
  • 31
  • 1
  • 4
1

The shortest way I found to fix it:

sudo chown -R $USER:www-data storage bootstrap/cache
DevonDahon
  • 7,460
  • 6
  • 69
  • 114