在 Apache2/Linux (LAMP) 上为 PHP 网站设置文件权限的最佳实践是什么? [英] What are the best practices setting file permissions for a PHP website on Apache2/Linux (LAMP)?

查看:35
本文介绍了在 Apache2/Linux (LAMP) 上为 PHP 网站设置文件权限的最佳实践是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

设置站点文件的最低权限是多少,以允许 apache2/php 执行代码,显示 html/css/js,以及对于某些文件更新设置下载和安装插件.

What is the minimum permissions to set the site files to, in order to allow apache2/php to execute code, show html/css/js, and for some files update settings download and install plugins.

我正在构建的网站是 Drupal 或 Wordpress.

The websites I am building are either Drupal or Wordpress.

我想设置权限,以便 www-data 具有最低权限,并且管理员(现在是我)有权允许他从 SSH 会话中执行任务而无需sudo.

I'd like to set permissions so that www-data has the minimum permissions and the admin (which is me for now) has permissions to allow him to do tasks from an SSH session without needing sudo.

我想补充一点,我可以通过 SSH 完全访问 LAMP 服务器.我所追求的是设置用户和组权限的最严格,因此也是最安全的方法,简而言之:

I'd like to add that I have full access to the LAMP server via SSH. What I am after is the most restrictive and hence the most secure way to set user and group permissions, so in short:

  • 什么组
  • 什么主人
  • 什么权限

对于所有站点文件,比如 wordpress为了达到

For all site files for say a wordpress In order to achieve

  • Apache 可以访问文件并执行 PHP
  • 对于某些特殊文件或文件夹,Wordpress 应该能够更改
  • 管理员无需使用 sudo 即可轻松更改文件

推荐答案

大多数情况下,目录的权限应该设置为 755.如果您将其设置为 777,那么文件就可以在那里写入.文件最多应该是 664.如果您使用 WP 编辑器,您可能需要这些文件是 666,但您确实应该在进行任何更改后将它们恢复为 664.除非指定,否则切勿指定大于 666 的文件.

Mostly the directory should have the permission set to 755. If you set it to 777 then the files can be written there. Files should be, at most, 664. If you use the WP editor, you might need these files to be 666 but you really should revert them back to 664 after making any changes. Never specify files greater than 666 unless specified.

有些主机只允许上传 777 权限,只能避免这种情况,并尝试为此联系主机.

Some hosting only allow uploads on 777 permission only avoid such and try contacting hosting for this.

https://codex.wordpress.org/Changing_File_Permissions

这篇关于在 Apache2/Linux (LAMP) 上为 PHP 网站设置文件权限的最佳实践是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆