apache and sftp permissions for wordpress automati

2019-02-18 07:53发布

问题:

It's my first time trying to set up Wordpress or any website on a cloud hosting. I am on Ubuntu server, and Wordpress is located in var/www/mydomain/public folder.

What I want to achieve is this: Both Wordpress (PHP) and SFTP users can access and modify the same files. And Wordpress should be able to do it's automatic update for plugins, etc.

This is what I have done so far:

  • I have chmodded this folder to 775 to allow group read/write permissions.
  • I have added apache user (www-data) and SFTP user (suser) both to group wp.
  • I have made wp as the group owner of all files inside the wordpress folder.

What works:

  • I can edit theme and plugin files with Wordpress's built-in theme/plugin editor.

What does not work:

  • Wordpress update still asks for the FTP details to carry out the update
  • When I create a new file with SFTP user, it's permissions will be 644, but they should be 775

What I've tried

  • I have tried all the steps here (answer by caf): A general linux file permissions question: Apache and WordPress
  • I have tried this: http://jeff.robbins.ws/articles/setting-the-umask-for-sftp-transactions
  • I have also tried adding umask 002 to my SFTP startup login files, but I do not know where they are located.

As far as I understand, the problem lies somewhere with the permissions/umask thing. I know very little about linux so this may be a stupid question with a simple solution, but I have no idea how to fix it.

UPDATE: I did not know that I would have to restart the ssh server. I did it with this command /etc/init.d/ssh restart and after that files created with SFTP have permissions 664 (as they are supposed to) Also, it seems that Apache has to be restarted as well, with this command: /etc/init.d/apache2 restart

However, Wordpress still won't do automatic update (asks for FTP credentials)

回答1:

If you're able to install the SSH2 PHP Module Wordpress will then give you the option to upgrade over SFTP.

In Ubuntu:

sudo apt-get install libssh2-php

In CentOS (EPEL required):

sudo yum install php-pecl-ssh2


回答2:

I was trying to do the same thing with Wordpress updates, until I realized that Wordpress only supports FTP which, confusingly, SFTP is not. From Wikipedia:

FTPS should not be confused with the SSH File Transfer Protocol (SFTP), an incompatible secure file transfer subsystem for the Secure Shell (SSH) protocol. It is also different from Secure FTP, the practice of tunneling FTP through an SSH connection.

I'm still trying to figure out if there's a secure way to do Wordpress updates automatically; I don't know yet whether or not FTPS is truly secure.