3
votes

I host WordPress on AWS EC2 (Ubuntu) and encounter the following error while updating plugins:

To perform the requested action, WordPress needs to access your web server. Please enter your FTP credentials to proceed. If you do not remember your credentials, you should contact your web host.

rwx permission has been granted to the user www-data. Here is what I do.

<!– language: lang-bash –>

# Add a new group
groupadd www-pub

# Add the user `www-data` to the group 'www-pub'
usermod -a -G www-pub www-data

# Change the ownership of '/var/www/' to 'ubuntu:www-pub'
chown -R ubuntu:www-pub /var/www

# Change the permissions of all the folders to 2775
find /var/www -type d -exec chmod 2775 {} +

# Change the permissions of all the files to 0664
find /var/www -type f -exec chmod 0664 {} +

As you can see, www-data has all the right permissions, but I am still required to enter the FTP credentials. What is the reason and how can I fix it?

4
The best way that I have found to do this is with Google Chrome or Firefox is to download the plugin: LastPass and it will fill in the login/password for you. Is that what you are looking for? - Leptonator
@Leptonator, no. wordpress requires to login in ftp with password but AWS EC2 provides me SSH-keys. I know that creating a password for ftp is a solution but I don't think this way is a good one. - SparkAndShine
Have you tried adding define('FS_METHOD', 'direct'); to your wp-config.php file? - Demosthenes
@Brandon yeah, I put it in the end of wp-config.php and it doesn't work. As @Corlax suggested, put it below the database information and now it works perfectly. - SparkAndShine

4 Answers

14
votes

There is a simple fix. Just edit file wp-config.php and write this code inside it.

First try this:

define('FS_METHOD', 'direct');

Note: Do not add this to the end of the file, but just below the database information on the top of the file.

define('FTP_USER', 'username'); // Your FTP username
define('FTP_PASS', 'password'); // Your FTP password
define('FTP_HOST', 'ftp.example.org:21'); // Your FTP URL:Your FTP port

Also please read this blog post.

6
votes

This means that WordPress is having limited permission for making changes in the folder that it was installed.

In-order to fix this, all that you need to do is provide necessary permissions for the same.

Run the following command in your terminal, PuTTY, or command line prompt after connecting to your Server via SSH.

sudo chown -R apache:apache /var/www/html

Checkout the below article for full details (Syam | MMWYS.Online):

How to fix the infamous issue of WordPress asking for FTP Credentials for Installing Plugins / Themes?

5
votes

I suspect that this answer explains why it isn't working.

Most Ubuntu web servers I have seen are set up a bit differently from what you're doing. I'm not sure what your reason is for doing it that way, but if you wanted to keep things simple you would just set the owner and group for all files to www-data:

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

That will grant the web server full access to all of your files in the web root. If you needed to grant any additional users access to those files, you would just add them to the www-data group.

usermod -a -G www-data someuser

The file permissions you've set up look good to me as-is.

#Change the permissions of all the folders to 2775
find /var/www -type d -exec chmod 2775 {} +

#Change the permissions of all the files to 0664
find /var/www -type f -exec chmod 0664 {} +

For reference, this answer explains what chmod 2775 (specifically the 2) means.

Essentially, it causes any new files to inherit the group of the directory. www-data in this case. This means the web server will have access to any files created by other users, without having to change the ownership or permissions of those files.

1
votes

You need to assign a user to your project.

For NGINX Servers:

sudo chown www-data:www-data -R <your_wordpress_dir>

For Apache Servers:

sudo chown apache:apache -R <your_wordpress_dir>

And change directory permissions:

sudo chmod 755 -R <your_wordpress_dir>