在 Amazon EC2 (Amazon Linux) 上为 WordPress 设置权限

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

Setting up permissions for WordPress on Amazon EC2 (Amazon Linux)

linuxwordpresspermissionsamazon-ec2

提问by smorris

I setup WordPress on an Amazon EC2 instance. It's using Amazon Linux and is a standard setup (just php5 and mysql).

我在 Amazon EC2 实例上设置了 WordPress。它使用 Amazon Linux 并且是标准设置(只有 php5 和 mysql)。

WordPress works fine, but there's some permission issues. Specifically I can't upload media, update permalink, plugins, etc. I have no write permission under the ec2-user and because I uploaded all the files over WinSCP the current owner is ec2-user.

WordPress 工作正常,但存在一些权限问题。具体来说,我无法上传媒体、更新永久链接、插件等。我在 ec2-user 下没有写权限,因为我通过 WinSCP 上传了所有文件,当前所有者是 ec2-user。

My question is what's the best way to correct this issue? I could probably fix it by changing ownership of all folders/files to root, but that's not a very elegant or dynamic solution.

我的问题是纠正这个问题的最佳方法是什么?我可以通过将所有文件夹/文件的所有权更改为 root 来修复它,但这不是一个非常优雅或动态的解决方案。

The path to my web directory is /var/www/html. Can I allow the ec2-user the correct permissions? Perhaps by having a group that both the Apache user and ec2-user share?

我的 Web 目录的路径是 /var/www/html。我可以允许 ec2-user 正确的权限吗?也许通过拥有一个 Apache 用户和 ec2-user 共享的组?

Any ideas would be appreciated

任何想法,将不胜感激

回答by markratledge

See http://blog.david-jensen.com/development/wordpress-amazon-ec2-apache-permissions-wordpress/among other Google results. He looks to have had good luck:

查看http://blog.david-jensen.com/development/wordpress-amazon-ec2-apache-permissions-wordpress/以及其他 Google 结果。他看起来运气不错:

I have been doing my best to figure out the Amazon EC2 Apache setup of permissions to enable WordPress to be able to manage all of the files on my Amazon EC2 instance without WordPress asking for FTP permissions when I try to upload a plugin or theme via the Admin site. I ended up having to give file and group ownership of the files in my html folder to apache user for WordPress to run correctly. http://www.chrisabernethy.com/why-wordpress-asks-connection-info/and its comments helped me reach this conclusion.

我一直在尽最大努力找出 Amazon EC2 Apache 权限设置,以便在我尝试通过管理站点。我最终不得不将 html 文件夹中文件的文件和组所有权授予 apache 用户,以便 WordPress 正确运行。 http://www.chrisabernethy.com/why-wordpress-asks-connection-info/及其评论帮助我得出了这个结论。

From the webpage:

从网页:

Run

sudo su chown -R apache:apache /vol/html

I then set permissions to what the hardening WordPress guide recommends for my html root as all my WordPress files are there as I am running MultiSite with multiple domains.

然后我将权限设置为强化 WordPress 指南为我的 html 根推荐的权限,因为我所有的 WordPress 文件都在那里,因为我正在运行具有多个域的 MultiSite。

find /vol/html/ -type d -exec chmod 755 {} \;
find /vol/html/ -type f -exec chmod 644 {} \;

As apache doesn't have a login I feel this is worth the risk though there is probably a better way to do this. I then added ec2-user to the apache group and changed the permissions of the wp-content folder to have group write permission 775.

由于 apache 没有登录名,我觉得这值得冒险,尽管可能有更好的方法来做到这一点。然后我将 ec2-user 添加到 apache 组并将 wp-content 文件夹的权限更改为具有组写入权限 775。

useradd -G apache ec2-user
sudo chmod -R 775 /vol/html/wp-content

This allows FileZilla or any other program logged in as ec2-user the ability to change files and folders in the wp-content folder only. If anyone has a better way of doing this I would like to know. I am only using SSH and SFTP to access the server with key files.

这允许 FileZilla 或任何其他以 ec2-user 身份登录的程序只能更改 wp-content 文件夹中的文件和文件夹。如果有人有更好的方法来做到这一点,我想知道。我只使用 SSH 和 SFTP 来访问带有密钥文件的服务器。

回答by stink

I came across this question searching for the answer. I set all ownership and group ownership to Apache. However, if I want to upload something ftp I have to ssh change permissions to ec2-user upload the file and change it back. I figured it was a small price to pay to have the permissions set to WordPress's recommended settings.

我遇到了这个问题,正在寻找答案。我将所有所有权和组所有权设置为 Apache。但是,如果我想上传一些 ftp,我必须通过 ssh 更改 ec2-user 上传文件的权限并将其更改回来。我认为将权限设置为 WordPress 的推荐设置是一个很小的代价。

回答by Chad Reitsma

I set the owner to ec2-user:apache, then perform the hardening, then adjust the group read+write permissions for the folders.

我将所有者设置为ec2-user:apache,然后进行加固,然后调整文件夹的组读写权限。

sudo chown -R ec2-user:apache /vol/html
sudo chmod -R 755 /vol/html

sudo find /vol/html/ -type d -exec chmod 755 {} \;
sudo find /vol/html/ -type f -exec chmod 644 {} \;

sudo chgrp -R apache /vol/html
sudo chmod -R g+rw /vol/html
sudo chmod -R g+s /vol/html

Then edit /wordpress-install/wp-config.php and define the fs_method

然后编辑 /wordpress-install/wp-config.php 并定义 fs_method

define('FS_METHOD', 'direct');

Now wordpress can update/upload, etc. And you can still SFTP files without changing the permissions every time.

现在 wordpress 可以更新/上传等。你仍然可以 SFTP 文件,而无需每次更改权限。

回答by DD.

http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/hosting-wordpress.html

http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/hosting-wordpress.html

To fix file permissions for the Apache web server

Some of the available features in WordPress require write access to the Apache document root (such as uploading media though the Administration screens). The web server runs as the apache user, so you need to add that user to the www group that was created in the LAMP web server tutorial.

Add the apache user to the www group.

[ec2-user wordpress]$ sudo usermod -a -G www apache Change the file ownership of /var/www and its contents to the apache user.

[ec2-user wordpress]$ sudo chown -R apache /var/www Change the group ownership of /var/www and its contents to the www group.

[ec2-user wordpress]$ sudo chgrp -R www /var/www Change the directory permissions of /var/www and its subdirectories to add group write permissions and to set the group ID on future subdirectories.

[ec2-user wordpress]$ sudo chmod 2775 /var/www [ec2-user wordpress]$ find /var/www -type d -exec sudo chmod 2775 {} \; Recursively change the file permissions of /var/www and its subdirectories to add group write permissions.

[ec2-user wordpress]$ find /var/www -type f -exec sudo chmod 0664 {} \; Restart the Apache web server to pick up the new group and permissions.

[ec2-user wordpress]$ sudo service httpd restart Stopping httpd:
[ OK ] Starting httpd: [ OK ]

修复 Apache Web 服务器的文件权限

WordPress 中的一些可用功能需要对 Apache 文档根目录的写访问权限(例如通过管理屏幕上传媒体)。Web 服务器以 apache 用户身份运行,因此您需要将该用户添加到在 LAMP Web 服务器教程中创建的 www 组。

将 apache 用户添加到 www 组。

[ec2-user wordpress]$ sudo usermod -a -G www apache 将 /var/www 的文件所有权及其内容更改为 apache 用户。

[ec2-user wordpress]$ sudo chown -R apache /var/www 将 /var/www 的组所有权及其内容更改为 www 组。

[ec2-user wordpress]$ sudo chgrp -R www /var/www 更改 /var/www 及其子目录的目录权限以添加组写入权限并设置未来子目录的组 ID。

[ec2-user wordpress]$ sudo chmod 2775 /var/www [ec2-user wordpress]$ find /var/www -type d -exec sudo chmod 2775 {} \; 递归修改/var/www及其子目录的文件权限,增加组写权限。

[ec2-user wordpress]$ find /var/www -type f -exec sudo chmod 0664 {} \; 重新启动 Apache Web 服务器以获取新组和权限。

[ec2-user wordpress]$ sudo service httpd restart 停止 httpd:
[ OK ] 启动 httpd: [ OK ]

回答by Hemant Arora

I tried the solution provided in the answer by @markratledgefor my AWS EC2 instance (Amazon Linux).

我尝试了@markratledge为我的 AWS EC2 实例 (Amazon Linux)提供的答案中提供的解决方案。

Wordpress(apache) was good, but SFTP(ec2-user) was giving permission errors.

Wordpress(apache) 很好,但是 SFTP(ec2-user) 给出了权限错误。

Then I tried the following:

然后我尝试了以下方法:

I added ec2-user to the apache group:

我将 ec2-user 添加到 apache 组:

usermod -a -G apache ec2-user

Next I set 'apache' as owner group and 'ec2-user' as owner user for the WordPress installation directory (/var/www/html in my case):

接下来,我将 'apache' 设置为所有者组,将 'ec2-user' 设置为 WordPress 安装目录(在我的情况下为 /var/www/html)的所有者用户:

chown -R apache:ec2-user /var/www/html

Finally, WordPress was happy and I could SFTP too. Thanks!

最后,WordPress 很高兴,我也可以使用 SFTP。谢谢!