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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 13:56:27  来源:igfitidea点击:

Laravel proper permissions

laravelnginxphp-7

提问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: enter image description here

我只是试图将我的 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, as777is 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-dataor _wwwor 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/

sflag 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 usermodwith the -aGoptions : usermod -aG $USER www-data

根据您引导项目的方式,存储文件夹上通常已经有一个 775 标志,另一个简单的解决方法是使用usermod以下-aG选项将您的 Web 服务器用户添加到您的组: usermod -aG $USER www-data

回答by Alexey Mezenin

You need to set permissions recursively (use -Roption):

您需要递归设置权限(使用-R选项):

chmod -R 777 storage