服务器上 Laravel 文件夹的正确权限

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/51312943/
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 17:53:43  来源:igfitidea点击:

Correct permission for Laravel folders on server

phplaravel

提问by Adis Azhar

I am currently about to deploy a Laravel app. One of my features is to generate a PDF and save the file in the storage folder. But the problem is, it only works when the storage folder has 777permission. Of course that is a big security risk once it is deployed. How to I solve it? Because if I don't 777permission, it returns a Warning: mkdir() [function.mkdir]: Permission denied in ...error.

我目前正准备部署 Laravel 应用程序。我的功能之一是生成 PDF 并将文件保存在存储文件夹中。但问题是,它仅在存储文件夹具有777权限时才有效。当然,一旦部署,这是一个很大的安全风险。我该如何解决?因为如果我不777许可,它会返回一个Warning: mkdir() [function.mkdir]: Permission denied in ...错误。

Thank you :)

谢谢 :)

回答by Nathan F.

These permissions should be set to 770on the storage folder.

这些权限应设置为770对存储文件夹。

This will allow the owner of the directory (ideally the maintenance web admin) read/write/execute. And it will allow the web group (ideally the group that the maintenance web-admin and the web server user are both in) to have read/write/execute permission. The 0 means that other users have no permissions in the directory. The directory should be owned by the maintenance web admin, with it's ownership group set to the web group.

这将允许目录的所有者(最好是维护网络管理员)读/写/执行。并且它将允许 web 组(理想情况下维护 web-admin 和 web 服务器用户所在的组)具有读/写/执行权限。0 表示其他用户在该目录中没有权限。该目录应由维护 Web 管理员拥有,并将其所有权组设置为 Web 组。

Example

例子

chown -R mywebadmin:www-data /var/www/html/mysite.com/
chmod -R 750 /var/www/html/mysite.com/ 
chmod -R 770 /var/www/html/mysite.com/storage

Result

结果

  • /var/www/html/mysite.com - Owned by mywebadmin, Group is www-data
    • Owner can write/read/execute
    • Group can read/execute
    • Others can do nothing
  • /var/www/html/mysite.com/storage - Owned by mywebadmin, Group is www-data
    • Owner can write/read/execute
    • Group can write/read/execute
    • Others can do nothing
  • /var/www/html/mysite.com - 归mywebadmin,集团所有www-data
    • 所有者可以写/读/执行
    • 组可以读取/执行
    • 别人无能为力
  • /var/www/html/mysite.com/storage - 归mywebadmin,组是www-data
    • 所有者可以写/读/执行
    • 组可以写/读/执行
    • 别人无能为力


There is a useful toolfor generating these permissions if you have a hard time remembering them.

如果您很难记住它们,有一个有用的工具可以生成这些权限。

Note: It is extremely dangerous to have write access for the web user in the directory. A better option would be creating a PHP script that changes it's headers for Content-Typeto application/octet-streamand having the PHP script generate the file it needs interanally without writing to the file system.

注意:对目录中的 Web 用户具有写访问权限是极其危险的。更好的选择是创建一个 PHP 脚本,将其标题更改为Content-Typetoapplication/octet-stream并让 PHP 脚本在不写入文件系统的情况下生成内部所需的文件。

回答by JHOAN B. HENRICHE

The default settings for server permissions is 754. Mostly.

服务器权限的默认设置是 754。主要是。