LEMP + wordpress 文件权限能够编辑、升级和使用 sftp 客户端 [英] LEMP + wordpress file permissions to be able to edit, upgrade and use sftp client

查看:17
本文介绍了LEMP + wordpress 文件权限能够编辑、升级和使用 sftp 客户端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在运行 nginx 的 debian 网络服务器上管理文件权限,以便 wordpress 可以编辑、上传和升级而无需使用 ftp.我还希望能够通过我的用户帐户使用 sftp 登录.

I am trying to manage file permissions on a debian webserver that runs nginx, so that wordpress can edit, upload and upgrade without having to use ftp. I also want to be able to login using sftp with my user account.

我知道之前有人问过这个问题,请参阅此处此处,但请按照这些答案中的步骤进行操作一直不满意.目前的设置如下所示:

I am aware of the fact that this question has been asked before, see here or here, but following the steps in those answers hasn't been satisfying. The setup currently looks as follows:

  • wordpress 文件夹位于 /var/www/html/

我创建了一个新用户(user")和组(group").服务器用户是www-data".

I made a new user ("user") and group ("group"). The server user is "www-data".

wordpress 文件夹中的所有文件都归 user:group 所有.

All files in the wordpress folder are owned by user:group.

user"和www-data"都设置为属于group".

Both "user" and "www-data" are set to belong to "group".

我更改了文件和文件夹权限,如下所示:

I changed file and folder permissions as follows:

find /var/www/html/ -type d -exec chmod 2775 {} +

find /var/www/html/ -type f -exec chmod 664 {} +

  • 我将默认 umask 设置为 0002.

  • I set the default umask to 0002.

    我认为这应该可行,但目前我可以在 wordpress 中编辑和上传文件,但不能更新 wordpress、功能或主题.

    I would have thought this should work, but currently I can edit and upload files from within wordpress, but not update wordpress, functions or themes.

    • 它也不适用于将组"设置为用户"和/或www-data"的默认组(通过编辑 /etc/passwd).

    或者,我在 /var/www/html/ 中创建了 user:www-data 拥有的所有文件,但也没有成功.

    Alternatively, I made all files in /var/www/html/ owned by user:www-data, but also without success.

    我似乎在没有 ftp 的情况下让 wordpress 更新的唯一方法是使 wordpress 文件夹及其所有文件归www-data"所有.不幸的是,结果是我无法使用 sftp 客户端上传文件(因为目标现在是一个不属于用户"的文件夹).

    The only way I seem to get wordpress to update without ftp is by making the wordpress-folder and all its files owned by "www-data". Unfortunately, the result of that is that I cannot upload files using an sftp-client (because the target is now a folder that is not owned by "user").

    这怎么可能?据我了解,这些步骤应该给 wordpress 适当的权限,但还是有问题.

    How can this be? As far as I understand these steps should give wordpress the proper permissions, but something still is wrong.

    非常感谢您的帮助.

    推荐答案

    我遇到了这个问题,我想我会分享我是如何在运行 PHP 7Ubuntu 上修复它的代码> 以防它可以帮助某人.我在阅读 这篇 文章概述了如何使用 PHP 5 完成.

    I ran into this issue and I figured that I would share how I fixed it on Ubuntu running PHP 7 in case it can help someone. I adapted the following after reading this article that outlines how it is done with PHP 5.

    Nginx 需要使用 PHP 池进行优化,以便将文件和文件夹的所有权授予用户.

    Nginx needs to be optimized with PHP pools in order to give ownership of files and folders to users.

    首先,您需要创建一个新的 PHP-FPM 内存池.为此,请复制默认内存池并将其重命名为您要与之关联的用户:

    First, you need to create a new PHP-FPM memory pool. Do this by copying the default memory pool and renaming it with the user that you want to associate it with:

    sudo cp /etc/php/7.0/fpm/pool.d/www.conf /etc/php/7.0/fpm/pool.d/username.conf
    

    编辑文件:

    sudo nano /etc/php/7.0/fpm/pool.d/username.conf
    

    浏览文件并在以下位置更改username:

    Go through the file and change username in the following locations:

    ; Start a new pool named 'www'.
    ; the variable $pool can we used in any directive and will be replaced by the
    ; pool name ('www' here)
    [username]
    
    
    ; Note: The user is mandatory. If the group is not set, the default user's group
    ;       will be used.
    user = username
    
    
    listen = /run/php/php7.0-fpm.username.sock
    

    现在您需要更新您的服务器块.您需要调整到正确的套接字以允许访问新创建的池.

    Now you need to update your server block(s). You will need to adjust to the correct sockets to allow access to the newly created pool.

    打开你的服务器配置文件:

    Open your server configuration file:

    sudo nano /etc/nginx/sites-available/default
    

    或者,如果您设置服务器块(虚拟主机),则:

    Or if you setup server blocks (virtual hosts), then:

    sudo nano /etc/nginx/sites-available/example.com
    

    编辑以下行并替换username:

    fastcgi_pass unix:/run/php/php7.0-fpm.username.sock;
    

    最后重启Nginx:

    sudo service nginx restart
    

    这篇关于LEMP + wordpress 文件权限能够编辑、升级和使用 sftp 客户端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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