我在这里看了一下,但没有找到关于最佳文件权限的任何细节。我也在这里看了一些WordPress表单的问题,但任何建议777的人显然需要上一节安全课。

总之,我的问题是这样的。我应该拥有以下权限:

存储所有WordPress内容的根文件夹 wp-admin wp-content wp-includes

那每个文件夹里的所有文件呢?


当前回答

为了确保您的网站是安全的,并且您为文件夹使用了正确的权限,请使用如下安全插件:

https://en-ca.wordpress.org/plugins/all-in-one-wp-security-and-firewall/

https://en-ca.wordpress.org/plugins/wordfence/

这些插件会扫描你的Wordpress安装,并通知你任何潜在的问题。这些还将警告您任何不安全的文件夹权限。除此之外,这些插件会建议你应该给文件夹分配什么权限。

其他回答

在wp_config文件中定义。

/var/www/html/Your-Project-File / wp-config.php

define( 'FS_METHOD', 'direct' );

Chown -更改文件/dirs的所有权。Ie。文件/dir的所有者更改为指定的所有者,但不会修改权限。

sudo chown -R www-data:www-data /var/www

对于那些在主文件夹下有wordpress根文件夹的用户:

apache Ubuntu * * /

将您的用户添加到www-data组:

CREDIT赋予www-data组写权限

你想在你的用户上调用usermod。那就是:

sudo usermod -aG www-data yourUserName

**假设www-data组存在

检查用户是否在www-data组: 组yourUserName

你应该得到这样的东西:

youUserName : youUserGroupName www-data

** youUserGroupName通常与您的用户名类似

递归地更改wp-content文件夹的组所有权,保持用户所有权 chown username:www-data -R youWebSiteFolder/wp-content/* 修改目录为“youWebSiteFolder/wp-content/” cd youWebSiteFolder / wp-content 递归更改文件夹和子文件夹的组权限以启用写权限: 找到。-type d -exec chmod -R 775 {} \;

/home/yourUserName/youWebSiteFolder/wp-content/的模式从0755 (rwxr-xr-x)更改为0775 (rwxrwxr-x)

递归地更改文件和子文件的组权限以启用写权限: 找到。-type f -exec chmod -R 664 {} \;

结果应该如下所示:

WAS:
-rw-r--r--  1 yourUserName www-data  7192 Oct  4 00:03 filename.html
CHANGED TO:
-rw-rw-r--  1 yourUserName www-data  7192 Oct  4 00:03 filename.html

等价于:

chmod -R ug+rw文件夹

文件的权限是664,目录的权限是775。

附注:如果有人在更新插件时遇到“无法创建目录”错误,请: server@user:~/domainame.com$ sudo chown用户名:www-data -R wp-content 当你在你的域的根。 假设:wp-config.php有 LocalHost上的FTP凭据 定义(“FS_METHOD”、“直接”);

对于OS X使用以下命令:

sudo chown -R www:www /www/folder_name

最好在https://wordpress.org/support/article/changing-file-permissions/上阅读wordpress文档

All files should be owned by the actual user's account, not the user account used for the httpd process Group ownership is irrelevant, unless there's specific group requirements for the web-server process permissions checking. This is not usually the case. All directories should be 755 or 750. All files should be 644 or 640. Exception: wp-config.php should be 440 or 400 to prevent other users on the server from reading it. No directories should ever be given 777, even upload directories. Since the php process is running as the owner of the files, it gets the owners permissions and can write to even a 755 directory.

我认为下面的规则是推荐的默认wordpress网站:

对于wp-content中的文件夹,设置0755权限: chmod -R 0755插件 chmod -R 0755上传 chmod -R 0755 upgrade 让apache用户成为wp-content目录的所有者: Chown apache上传 Chown apache升级 Chown apache插件