Laravel 适当的权限
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37649269/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel proper permissions
提问by MattJ
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:
我只是试图将我的 Laravel 项目更改为在 Nginx 而不是 Apache 上运行,但无法获得正确的权限。真的不知道接下来要尝试什么。目前他们在这里:
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
我什至给了存储文件夹的 777 权限,但没有任何效果。我在博客上有一个管理面板,它总是不断抛出
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.
我正在使用 Nginx、PHP 7.0、MySQL。该网站是使用 Laravel 框架编写的。
回答by Ganesh Ghalame
This will work, as777
is a security risk
这将起作用,因为777
存在安全风险
sudo chmod -R o+w storage/
sudo chmod -R 775 storage/
回答by Ankit Balyan
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.
首先,检查Nginx www conf文件中分配的 /etc/php/7.0/php-fpm.d/www.conf
用户用户可能是www-data
或_www
或任何其他。
Then change the ownership of the project folder as
然后将项目文件夹的所有权更改为
sudo chown $USER:www-data -R ~/Laravel/PBlog/
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/
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.
s
标志意味着,在文件夹内添加/创建的任何文件/文件夹都将获得相同的权限。
回答by elgamine
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
根据您引导项目的方式,存储文件夹上通常已经有一个 775 标志,另一个简单的解决方法是使用usermod
以下-aG
选项将您的 Web 服务器用户添加到您的组:
usermod -aG $USER www-data
回答by Alexey Mezenin
You need to set permissions recursively (use -R
option):
您需要递归设置权限(使用-R
选项):
chmod -R 777 storage