WordPress needs the FTP credentials to update plugins

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.

Read More

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?

Related posts

5 comments

  1. 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.

  2. 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?

  3. 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.

  4. 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> 
    
  5. Add this line define( 'FS_METHOD', 'direct' ); of code in your wp-config.php file after define( 'WP_DEBUG', true );.

    So it should be like this:

    define( 'WP_DEBUG', true );
    
    /* Add any custom values between this line and the "stop editing" line. */
    
    define( 'FS_METHOD', 'direct' );
    
    /* That's all, stop editing! Happy publishing. */
    

    Save the file and try again.

Comments are closed.