WordPress asking for my FTP credentials to install plugins

WordpressPluginsFtpWordpress ThemingAdmin

Wordpress Problem Overview


I installed a WordPress blog in my local system. But when I try to add plugins from admin it asks for FTP access. What do I need to configure for WordPress to be able to upload without FTP?

Wordpress Solutions


Solution 1 - Wordpress

Try to add the code in wp-config.php:

define('FS_METHOD', 'direct');

Solution 2 - Wordpress

If you are using Ubuntu.

sudo chown -R www-data:www-data PATH_TO_YOUR_WORDPRESS_FOLDER

Solution 3 - Wordpress

"Whenever you use the WordPress control panel to automatically install, upgrade, or delete plugins, WordPress must make changes to files on the filesystem.

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 asked for FTP credentials so that WordPress can try to do what it needs to via FTP."

Solution: In order to find out what user your instance of apache is running as, create a test script with the following content:

<?php echo(exec("whoami")); ?>

For me, it was daemon and not www-data. Then, fix the permission by:

sudo chown -R daemon /path/to/your/local/www/folder

Solution 4 - Wordpress

I changed the ownership of the wordpress folder to www-data recursively and restarted apache.

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

It worked like a charm!

Solution 5 - Wordpress

On OSX, I used the following, and it worked:

sudo chown -R _www:_www {path to wordpress folder}

_www is the user that PHP runs under on the Mac.

(You may also need to chmod some folders too. I had done that first and it didn't fix it. It wasn't until I did the chown command that it worked, so I'm not sure if it was the chown command alone, or a combination of chmod and chown.)

Solution 6 - Wordpress

If during installation of a plugin, Wordpress asks for your hostname or FTP details. Then follow these steps:

Login to your server and navigate to /var/www/html/wordpress/. Open wp-config.php and add this line after define(‘DB_COLLATE’)

define('FS_METHOD', 'direct');

If you get "Could not create directory" error. Give write permissions to your wordpress directory in recursive as

chmod -R go+w wordpress

NOTE. For security, revoke these permissions once you install a plugin as

chmod -R go-w wordpress

Solution 7 - Wordpress

I did a local install of WordPress on Ubuntu 14.04 following the steps outlined here and simply running:

sudo chown -R www-data:www-data {path_to_your_project_directory}

solved my issue with downloading plugins. The only reason I'm leaving this post here is because when I googled my issue, this was one of the first results and it led me to the solution to my problem.

Hope this one helps to anyone!

Solution 8 - Wordpress

From the first hit on Google:

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

This is rather normal in most shared hosting environments - the files are stored as the user, and Apache runs as user apache or httpd. This is actually a good security precaution so exploits and hacks cannot modify hosted files. You could circumvent this by setting all WP files to 777 security, but that means no security, so I would highly advise against that. Just use FTP, it's the automatically advised workaround with good reason.

Solution 9 - Wordpress

There's a lot of similar responses to this question, but none of them fully touch on the root cause. Sebastian Schmid's comment on the original post touches on it but not fully. Here's my take as of 2018-11-06:

Root Cause

When you try to upload a plugin through the WordPress admin interface, WordPress will make a call over to a function called "get_filesystem_method()" (ref: /wp-admin/includes/file.php:1549). This routine will attempt to write a file to the location in question (in this case the plugin directory). It can of course fail here immediately if file permissions aren't setup right to allow the WordPress user (think the user identity executing the php) to write the file to the location in question.

If the file can be created, this function then detects the file owner of the temporary file, along with the file owner of the function's current file (ref: /wp-admin/includes/file.php:1572) and compares the two. If they match then, in WordPress's words, "WordPress is creating files as the same owner as the WordPress files, this means it's safe to modify & create new files via PHP" and your plugin is uploaded successfully without the FTP Credentials prompt. If they don't match, you get the FTP Credentials prompt.

Fixes

  1. Ensure the plugin directory is writable by the identity running your php process.

  2. Ensure the identity that is running your php process is the file owner for either:

    a) All WordPress application files, or...
    b) At the very least the /wp-admin/includes/file.php file

Final Comments

I'm not overly keen on specifically applying file ownership to the file.php to work around this issue (it feels a tad hacky to say the least!). It seems to me at this point that the WordPress code base is leaning towards having us execute the PHP process under the same user principal as the file owner for the WordPress application files. I would welcome some comments from the community on this.

Solution 10 - Wordpress

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/');

FTP_BASE is the full path to the "base"(ABSPATH) folder of the WordPress installation FTP_CONTENT_DIR is the full path to the wp-content folder of the WordPress installation. FTP_PLUGIN_DIR is the full path to the plugins folder of the WordPress installation.

Solution 11 - Wordpress

We had the same problem as part of a bigger problem. The suggested solution of

define('FS_METHOD', 'direct');

hides that window but then we still had problems with loading themes and upgrades etc. It is related to permissions however in our case we fixed the problem by moving from php OS vendor mod_php to the more secure php OS vendor FastCGI application.

Solution 12 - Wordpress

First move to your installation folder (for example)

cd /Applications/XAMPP/xamppfiles/

Now we’re going to modify your htdocs directory:

sudo chown -R daemon htdocs

Enter your root password when prompted, then finish it out with a chmod call:

sudo chmod -R g+w htdocs

Solution 13 - Wordpress

I was facing the same problem! I've added the code below in wp-config.php file (in any line) and it's working now!

define('FS_METHOD', 'direct');

Solution 14 - Wordpress

For me the the process that solved, to be able to work on my localhost using Ubuntu, was: (of course you must replace myUser by your user, whoami show it for you if you dont know)

  • Include myself on www-data group (to be able to access and edit files without sudo):

    sudo usermod -aG www-data myUser
    
  • Set myself and this group as files owners:

    sudo chown -R myUser:www-data /var/www/html
    
  • Set a major permission for the group (the group must write too):

    sudo find . -type f -exec chmod 664 {} \;
    sudo find . -type d -exec chmod 775 {} \;
    
  • Then add this line on config.php

    define('FS_METHOD', 'direct');
    

Solution 15 - Wordpress

As mentioned by Niels, this happens because the server process user can't write to the Wordpress folder.

But here's the thing a lot of articles don't explain. It's the owner of the php process, not the nginx process. If you try to change the nginx owner, it won't solve this.

To solve it, try running ps aux to see which user owns the php-fpm process. Then check that user is the same user as the owner of the wordpress folder, or can at least write to it. If the user can't write to it, you'll need to change permissions and/or ownership of the folder; or put the two users (server owner and wordpress folder owner) in a common group which can write to the folder; or change php.ini "user" property to a user that can write to the folder.

Solution 16 - Wordpress

define('FS_METHOD', 'direct'); 

Add this to wp-config.php

If the issue still persist , you can try setting permission of plugin folder to 755 Or in linux you can set it by this command

Chmod -R 755

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionsasi kanthView Question on Stackoverflow
Solution 1 - WordpressnickleView Answer on Stackoverflow
Solution 2 - WordpressNanhe KumarView Answer on Stackoverflow
Solution 3 - WordpressAboozar RajabiView Answer on Stackoverflow
Solution 4 - WordpressKawaiKxView Answer on Stackoverflow
Solution 5 - WordpressKennyView Answer on Stackoverflow
Solution 6 - WordpressAbhishek RathoreView Answer on Stackoverflow
Solution 7 - WordpressHiren GohelView Answer on Stackoverflow
Solution 8 - WordpressNiels KeurentjesView Answer on Stackoverflow
Solution 9 - WordpressMatt WoodwardView Answer on Stackoverflow
Solution 10 - WordpressPurvik DhorajiyaView Answer on Stackoverflow
Solution 11 - WordpressmaltaView Answer on Stackoverflow
Solution 12 - WordpressBenja GarridoView Answer on Stackoverflow
Solution 13 - WordpresserovereView Answer on Stackoverflow
Solution 14 - WordpressGiovan CruzView Answer on Stackoverflow
Solution 15 - WordpressmahemoffView Answer on Stackoverflow
Solution 16 - WordpressShebin KPView Answer on Stackoverflow