Stop & Fix WordPress Ask for FTP Credentials Upgrade and Install New themes, plugins

Have you ever got the message Connection Information and a form is prompting you to enter FTP information when doing updates, delete, install new themes or plugins?
I saw that message after move all my hosting files from default location to other place that allows my website running on VPS with lower permission to increase the security.
This problem is very easy to fix and stop WordPress Ask for FTP Credentials again but you will frustrating sometimes of trying to get it done if you don’t know the causing of this problem.

Stop & Fix WordPress Ask for FTP Credentials
Stop & Fix WordPress Ask for FTP Credentials

What is Causing of WordPress Asking for FTP details ?

When automatically upgrading, installing or updating a theme or plugin or the WordPress core, WordPress needs to make changes to the file system.

Before making any changes, WordPress first checks to see whether or not it has access to directly manipulate the file system.

If WordPress does not have the necessary permissions to modify the filesystem directly, you will be prompted to enter your FTP user account information.

And the causing of this problem is:

WordPress asks for your FTP credentials when it can’t access the files directly. This is usually caused by PHP running as the apache user (mod_php or CGI) rather than the user that owns your WordPress files.

What Can I Do To Stop and Fix WordPress Ask for FTP Credentials?

The easiest way to solve this problem is add the following FTP information to your wp-config.php

define('FS_METHOD', 'direct');
define('FTP_BASE', '/usr/home/username/public_html/my-site.example.com/wordpress/');
define('FTP_CONTENT_DIR', '/usr/home/username/public_html/my-site.example.com/wordpress/wp-content/');
define('FTP_PLUGIN_DIR ', '/usr/home/username/public_html/my-site.example.com/wordpress/wp-content/plugins/');
// define('FTP_PUBKEY', '/home/username/.ssh/id_rsa.pub');
// define('FTP_PRIKEY', '/home/username/.ssh/id_rsa');
define('FTP_USER', 'my-ftp-username');
define('FTP_PASS', 'my-ftp-password');
define('FTP_HOST', 'ftp.my-site.example.com');
// define('FTP_SSL', false);

Problem Solved?

  • No! WordPress still asking me again with that stupid message!
  • Just wait, I haven’t installed FTP service on my server!

Moving on. If you answer me like that, you had or need the permission to control your server.
For this first method, it’s fixing your problem on 99.9% of shared hosting.
For the second method which can fix your problem in any case, we’re going to find out which user owns the web server and give that user ownership of your WordPress installation.

Looking for web server ownership process

After test and research on Internet in many times, I realised it’s the owner of the PHP process, not the web server software processes like Apache, Nginx, …
So try running ps aux | grep php to see which user owns the PHP process. Here is my case:

$ ps aux | grep php
root      1249  0.0  0.1 290648  5956 ?        Ss   Sep17   0:01 php-fpm: master process (/etc/php/php-fpm.conf)              
http      1278  0.0  1.0 374340 39492 ?        S    Sep17   0:21 php-fpm: pool www                                            
http      1279  0.0  1.1 374808 41460 ?        S    Sep17   0:12 php-fpm: pool www                                            
http      3934  0.0  1.0 374852 38048 ?        S    Sep17   0:17 php-fpm: pool www

It tells me that the PHP process is running under the user http.
So, a quick solution will be to issue this command and give user recursive ownership of the whole WordPress installation

$ sudo chown -hR http:http PATH_TO_YOUR_WORDPRESS_FOLDER

Replacing http with whatever user is yours.
Notes: If you are using Ubuntu. The default user and group of your PHP and Web Server software is www-data.

I really hope that helps someone, I spent ages being confused over this “feature”! If you have any more details or information, or if this works for you, then please add a comment below

24 thoughts on “Stop & Fix WordPress Ask for FTP Credentials Upgrade and Install New themes, plugins”

    • That depends on the webserver you’re using. If you’re using Apache, you have to check (e.g. in Task Manager) what user it is running under and grant all privileges for your WP folder to that user. If it’s IIS, you need to grant appropriate rights to the IUSR_COMPUTERNAME user.

  1. Yiannis’s solution worked for me too.

    I don’t understand why WordPress should suddenly need this directive. I’ve been looking at permissions as the problem, which have all been working just fine until recently, but turns out on my system all it wanted was this line in wp-config.php:

    define(‘FS_METHOD’,’direct’);

    Thanks Yiannis.

  2. Pingback: What Are Ftp Credentials Wordpress | Windranger4
  3. I used this method and it fixed the FTP question, but had a new issue crop up. The plugin installer said it could not create the directory.

  4. Working Fine, I tried all possible ways and finally I am able to do it. So much thanks for explaining right way to process to fix wordpress issue with FTP Credential again.
    Thanks.

  5. define(‘FS_METHOD’, ‘direct’); worked for me, but I’m also wondering if this is secure – I mean, I have a FTP password on this file, I need to know what could go wrong.

    • You would use define( FS_METHOD = ‘direct’ ); in a false positive scenario such as this one: you are part of a trusted team whose members all upload files through their own account. PHP runs as its own separate user. WordPress will assume that this is an at-risk environment and will not default to ‘direct’ mode. In reality it’s only shared with users you trust and as such ‘direct’ mode is safe. In this case you should use define( FS_METHOD = ‘direct’ ); to force WordPress to write files directly.

  6. Hello,
    I am facing a strange issue post that, I am getting An error occurred while updating [wordpress or plugins]: Could not create directory.

    thanks in advance

    • Let’s check the permission and owners of your folders and files. The error message was told that you (your wordpress) don’t allow to write on that location.
      Do you have a role to access your server throught command line?

  7. WordPress automatically lets you delete and upgrade the plugin.But suddenly I found this FTP authentication issue which is embarrassing.The above code which you shared works fine and solved this issue.Thanks for this

Comments are closed.