Search
Close this search box.

How to Stop WordPress Asking for FTP details to Upgrade Plugins

WordPress makes the experience of keeping plugins and the core installation an easy job and that goes a long way to making it one of the most popular Content Management Systems.

From the Admin Dashboard you can see how many updates there are and are given links to upgrade automatically.

WordPress 3.x even introduced the ability to upgrade everything all at the same time.

For most installations, this is all a seamless single-click operation.

So, why do some people get an additional form pop up asking for their ftp account details?

And more importantly, how do you make it go away – forever!

Here’s an explanation of why WordPress asks for this information and what you can do minimise or even stop typing your details in each time you perform an upgrade.

Or you can just jump to the quick fix and see if it works for you.  Who cares how, right?

Why does WordPress ask for FTP Connection Information?

When automatically upgrading, installing or updating a plugin or the WordPress core from the Admin Dashboard, WordPress needs to make changes to the file system (your web hosted site).

Before making the changes, it first needs to check whether it has the correct permissions to do this.

If it doesn’t, you will be prompted to enter your FTP user account information (see image below) as your FTP user account will have the correct permissions to update the files on your website and WordPress can carry on using the FTP user.

Why can’t WordPress Update the File System?

Sounds a bit daft doesn’t it?

To understand what is happening here, we must understand how WordPress attempts to write files to the file system and that means poking around in the core files.  Yay!

Whenever WordPress writes to the file system, it uses functions from the library wp-admin/includes/file.php specifically the get_filesystem_method() function.
if ( ! $method && function_exists('getmyuid') && function_exists('fileowner') ){
        if ( !$context )
            $context = WP_CONTENT_DIR;
        $context = trailingslashit($context);
        $temp_file_name = $context . 'temp-write-test-' . time();
        $temp_handle = @fopen($temp_file_name, 'w');
        if ( $temp_handle ) {
            if ( getmyuid() == @fileowner($temp_file_name) )
                $method = 'direct';
            @fclose($temp_handle);
            @unlink($temp_file_name);
        }
     }

The code snippet above creates a temporary file and then checks to see if the file is owned by the same user that owns the currently running script.

Plugin installations will be running the script wp-admin/plugin-install.php.

It all depends on the way that your web host has setup WordPress to run in your environment.

In most cases, the web server (usually Apache) will be given ownership to run and update all WordPress installations, mostly by running under your user account.

Sometimes though, ISPs will run the web server under a system account that does not have direct ownership of your files.

In that circumstance you’ll get the FTP Connection Information form popping up.

How Can I Fix This?

There are a couple of ways to get rid of the FTP Connection Information form.

The first method will likely only work if you have your own dedicated or private server with root ssh access.

For 99.9% of shared hosting, you are unlikely to have the privileges required to muck around with the web server settings and that is what’s needed.  If this is you, jump to the quick fix.

For this first method, we’re going to find out which user owns the web server and give that user ownership of your WordPress installation.

We’re assuming you’ve got a Linux box running Apache as the web server as that’s the most popular hosting plan type.

Login to your server box using ssh.

Find out what user is running the web server by typing:
ps aux | grep ‘apache’
The command will return something similar to this:
root@ubuntu-box:/# ps aux | grep ‘apache’
root 1933 0.0 2.3 44900 12032 ? Ss Aug25 15:09 /usr/sbin/apache2 -k start
webuser 2572 0.0 6.2 66468 30246 ? S Mar10 0:04 /usr/sbin/apache2 -k start
webuser 6045 0.0 6.4 66884 31562 ? S Mar10 0:07 /usr/sbin/apache2 -k start
webuser 6786 0.0 5.6 64156 27632 ? S Mar10 0:10 /usr/sbin/apache2 -k start

This tells you that the web server is running under the user webuser.

You can now give that user recursive ownership (all subfolders) of your WordPress installation using the command:
chown -hR webuser:webuser /var/mydomain.com/public_html/wordpress/
Replacing webuser with whatever user is running your Apache server and the last part with the direct path to your root WordPress installation folder.

Note: Some chown versions are different.  Type chown –help to get info on your version.

The Quick Fix

Ok, so you’re on a typical shared hosting plan and just want this damned FTP Connection Information form to go away.

Here’s what to do.

Edit your wp-config.php file (found in the root of the WordPress installation) and add the following lines somewhere in between the start :
/** Setup FTP Details **/
define("FTP_HOST", "localhost");
define("FTP_USER", "your-ftp-username");
define("FTP_PASS", "your-ftp-password");

Replacing the values with whatever you use on the FTP Connection Information form.

Once saved and uploaded if making the changed from a local copy, you should no longer be prompted for FTP Connection Information.

Dublin WordPress

If you live in and around Dublin and use WordPress as a blogger, developer, designer, trainer, business venture etc, come and join us on the last Thursday of every month at the Bull & Castle (next to Christ Church) from 6.30pm onwards.

More details at http://www.meetup.com/Dublin-WordPress/

Was this article helpful?
YesNo

11 Responses

  1. This worked for me

    Add below code in wp-config.php

    define(‘FS_METHOD’, ‘direct’);

    1. Yeah, for some reason even though I knew the permissions were set up properly it still wasn’t working. I’m pretty familiar with linux and tried every combination possible, even at one point setting permissions on the entire wordpress directory to 777. No dice. getmyuid was returning the default user on the system, and the owner of the temp file created was apache. Everyone’s in group apache and the files were all group rwx.

      Anyway, defining FS_METHOD did it for me!

      1. I tried also with defining FS_METHOD but no luck, am I still doing someting wrong?
        define( ‘FTP_USER’, ‘username’ );
        define( ‘FTP_PASS’, ‘password’ );
        define( ‘FTP_HOST’, ‘ftp.example.org:21’ );
        define(‘FS_METHOD’, ‘direct’);

        also tried:
        define( ‘FTP_USER’, ‘username’ );
        define( ‘FTP_PASS’, ‘password’ );
        define( ‘FTP_HOST’, ‘localhost’ );
        define(‘FS_METHOD’, ‘direct’);

        I am getting this error all the time:

        Internal Server Error

        The server encountered an internal error or
        misconfiguration and was unable to complete
        your request.

        Please contact the server administrator,
        [email protected] and inform them of the time the error occurred,
        and anything you might have done that may have
        caused the error.

        More information about this error may be available
        in the server error log.

        Additionally, a 500 Internal Server Error
        error was encountered while trying to use an ErrorDocument to handle the request.

        Apache/2 Server at http://www.my-site-example.com Port 80

        ——————————————–

        I have this code also in there from wordfence security or wp seo plugin, maybe this interferes?
        # BEGIN WordPress

        RewriteEngine On
        RewriteBase /
        RewriteRule ^index.php$ – [L]
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule . /index.php [L]

        # END WordPress

    2. I tried this i combination with the previous mentioned methods but no luck, any more ideas someone?
      define( ‘FTP_USER’, ‘username’ );
      define( ‘FTP_PASS’, ‘password’ );
      define( ‘FTP_HOST’, ‘ftp.example.org:21’ );

      also tried:
      define( ‘FTP_USER’, ‘username’ );
      define( ‘FTP_PASS’, ‘password’ );
      define( ‘FTP_HOST’, ‘localhost’ );

  2. I was going through this same issue, as well as unable to upload media, install/uninstall themes/plugins, etc. Nothing was working and I found what fixed it for me was to enable php to run as FastCGI in your hosting control panel.

  3. Put your FTP credentials directly in wp-config.php like this:
    define( ‘FTP_USER’, ‘username’ );
    define( ‘FTP_PASS’, ‘password’ );
    define( ‘FTP_HOST’, ‘ftp.example.org:21’ );

  4. none of this works, if i chmod or chown ( i am not sure what user is or how to find it)
    ftp in wp-config or fsmethod direct i then get cant create directory errors

  5. Thanks! That was a very helpful tutorial. I had those issues on LAMP install. Solved it through:
    sudo chown -hR www-data:www-data /var/www/html/wordpress/

    1. This worked for me. My wordpress installation was under the /var/www/html I had deleted the /wordpress directory, so I ran with sudo chown -hR apache:apache /var/www/html/