一个一般的 linux 文件权限问题:Apache 和 WordPress

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

A general linux file permissions question: Apache and WordPress

linuxapachewordpresspermissions

提问by kovshenin

I moved from a shared hosting to a VPS a few weeks ago and I'm having these annoying permission issues with WordPress. You know you can download and upgrade plugins (and wordpress itself) from the admin panel, but since I moved it started asking me my FTP credentials, which is kinda slow when I have to update ~20 plugins.

几周前我从共享主机转移到 VPS,我遇到了这些烦人的 WordPress 权限问题。你知道你可以从管理面板下载和升级插件(和 wordpress 本身),但是自从我移动它开始询问我的 FTP 凭据,当我必须更新大约 20 个插件时,这有点慢。

I think this should be some kind of rights issue. I looked that the shared hosting wordpress files, they all belong to the username and group kovshenin (kovshenin:kovshenin) and the files are -rw-r--r-- and the directories are drwx-r-xr-x.

我认为这应该是某种权利问题。我查看了共享托管wordpress文件,它们都属于用户名和组kovshenin(kovshenin:kovshenin),文件是-rw-r--r--,目录是drwx-r-xr-x。

On my VPS apache runs under apache:apache and my files are kovshenin:kovshenin. What should I do to make them readable and writable by both kovshenin and apache?

在我的 VPS 上,apache 在 apache:apache 下运行,我的文件是 kovshenin:kovshenin。我应该怎么做才能使它们对 kovshenin 和 apache 可读和可写?

Also, I changed the permissions to 0777 for all files and folders of my wordpress installation, that allowed me to install and delete plugins without FTP, but when I pushed to automatic upgrade to WordPress 2.8.1 it still asked me for my FTP account. Is that a wp issue or did I miss something?

此外,我将 wordpress 安装的所有文件和文件夹的权限更改为 0777,这允许我在没有 FTP 的情况下安装和删除插件,但是当我推送到自动升级到 WordPress 2.8.1 时,它仍然要求我提供我的 FTP 帐户。这是 wp 问题还是我错过了什么?

Thanks.

谢谢。

Update: I managed to run idand id www-dataon the MediaTemple shared hosting. User kovshenin is in group kovshenin, and www-data is in group www-data. No more groups. What's the trick?

更新:我设法运行id,并id www-data在MEDIATEMPLE共同主办。用户 kovshenin 在 kovshenin 组中,www-data 在 www-data 组中。没有更多的团体。有什么诀窍?

Another updateOkay, I added the apacheuser to the kovsheningroup, my wordpress files are kovshenin:kovsheninwith rw-rw-r--permissions and drwxrwxr-xpermissions on directories, but something is still wrong. The user apachecan access the files and folders, I can use the online Themes and Plugins editor in the wordpress admin panel, I'm able to make changes to the .htaccess file from within wordpress, but plugin/theme installation still asks me for FTP credentials!

另一个更新好的,我将apache用户添加到kovshenin组中,我的 wordpress 文件kovshenin:kovshenin具有rw-rw-r--权限和drwxrwxr-x目录权限,但仍然有问题。用户apache可以访问文件和文件夹,我可以使用 wordpress 管理面板中的在线主题和插件编辑器,我可以从 wordpress 中更改 .htaccess 文件,但插件/主题安装仍然要求我提供 FTP证书!

Any ideas? Thanks.

有任何想法吗?谢谢。

回答by caf

What should I do to make them readable and writable by both kovshenin and apache?

我应该怎么做才能使它们对 kovshenin 和 apache 可读和可写?

  • Create a new group, say "wordpress".
  • Add both koveshenin and www-data users to the wordpress group.
  • Change the group owner of all the files to wordpress (using chgrp).
  • Make sure all the files are group writeable.
  • Set the g+s (setgid) permission bit on all the directoriesof interest.
  • Make sure kovshenin and apache's default umask includes group read & write permission.
  • 创建一个新组,说“wordpress”。
  • 将 koveshenin 和 www-data 用户添加到 wordpress 组。
  • 将所有文件的组所有者更改为 wordpress(使用 chgrp)。
  • 确保所有文件都是组可写的。
  • 在所有感兴趣的目录上设置 g+s (setgid) 权限位。
  • 确保 kovshenin 和 apache 的默认 umask 包括组读写权限。

The second last step is the trick. It means that whenever kovshenin or apache creates a file in those directories, the group owner will be set to wordpress (instead of kovshenin or apache).

最后一步是诀窍。这意味着每当 kovshenin 或 apache 在这些目录中创建文件时,组所有者将被设置为 wordpress(而不是 kovshenin 或 apache)。

回答by KahWee Teng

You can give ownership to www-data according to here.

您可以根据此处为 www-data 授予所有权。

Run the following command in your WordPress directory (sudo required):

在您的 WordPress 目录中运行以下命令(需要 sudo):

sudo chown -Rf www-data *

Works for Apache.

适用于 Apache。

回答by Reza S

Assuming your wordpress install directory is /var/www/htmlto mass change all the files and directories to the proper permission use:

假设您的 wordpress 安装目录是/var/www/html将所有文件和目录批量更改为正确的权限使用:

sudo  find /var/www/html/ -type d -exec chmod 775 {} \;
sudo  find /var/www/html/ -type f -exec chmod 664 {} \;

To mass change the owner group of everything use:

要批量更改所有内容的所有者组,请使用:

sudo chgrp -R <desired_username>.<desired_groupname> /var/www/html

回答by Manje Brinkhuis

Currently, adding define('FS_METHOD', 'direct');to wp-config.php might do the trick. Not sure that would have worked in '09 though. See herefor my similar case using nginx. I found that it was an essential step.

目前,添加define('FS_METHOD', 'direct');到 wp-config.php 可能会奏效。不确定这在 09 年是否有效。请参阅此处了解我使用 nginx 的类似案例。我发现这是必不可少的一步。

回答by Fede

I had the same problem and I solved it turning off PHP 'safe_mode' in plesk, now WP can create folders and move files without any problems.

我遇到了同样的问题,我在 plesk 中关闭 PHP 'safe_mode' 解决了这个问题,现在 WP 可以创建文件夹并移动文件而没有任何问题。

I hope this help you.

我希望这对你有帮助。