5min Fix: WordPress Asking for FTP Credentials

A very common problem we solve at Utimize almost every day: WordPress has suddenly asked for FTP credentials to proceed with certain plugin installations and routine theme and core updates.

Some questions may arise:

  • Is it safe to provide this information to WordPress?
  • How will these credentials be stored?
  • My hosting uses SFTP, so how do I proceed?

The resolution of this problem is quite simple and can be applied in almost any situation, regardless of your web server.

Why WordPress asks for FTP credentials?

Simply put, whenever a file needs to be changed or added to the disk, the user making the modification must have specific permissions to write such information on the server. A folder or file created by the “root” user can never be modified by the “www-data” user, so WordPress cannot process any activity that involves changing information on the disk.

Another very common situation is when the file or folder is owned by the correct user but does not have write permissions. This is how it looks:

How to fix: “WordPress Asking for FTP Credentials”

There are a few ways to fix the problem, and the most common and easier is through wp-config.php. If you have access to your files, either via SFTP, FTP(s), SSH, etc., take a look at the steps below:

NOTE: If you host your site on Pantheon, make sure that “Development Mode” is set to SFTP instead of Git.

Using FS_METHOD 

Step 1 – Open the file “wp-config.php”. Most of the time, it will be in the root folder of WordPress.

Step 2 – Add the directive below before the line ‘if ( !defined(‘ABSPATH’) )’:

define( 'FS_METHOD','direct' );

Step 3 – Open the WordPress dashboard and try to update or install something. If you have already opened the dashboard on any tabs, remember to refresh it so that the previously added settings take effect.

If the issue has not been resolved, continue to the next method.

Fixing Permissions through (S)FTP

NOTE: This method is able to correct the write permissions of a given file. If the file or folder is owned by the root user, proceed to the next method.

Step 1 – Access your website files and folders using an FTP client, e.g. FileZilla.

Step 2 – Go to the wp-content folder.

Step 3 – Select the “plugins” folder with the right mouse button and click on “File permissions.”

Step 4 – Select the checkboxes as shown in the screenshot below:

Access the WordPress dashboard again and verify if the problem persists. If not resolved, make sure that the folder “wp-content/plugins” is not owned by the root user. You can verify this through the “Owner/Group” column on FileZilla.

In case of the root user owning the plugin folder, ownership change will be required.

Fixing Folder Ownership through SSH

NOTE: Incorrect actions using the root user can result in serious problems with your server. Only proceed with the steps below if you are completely sure of what you are doing. In any case, ask your hosting provider to do the following:

Step 1 – Access SSH using the root user.

Step 2 – If you want to change ownership of all WordPress files and folders, you can use recursion on the WordPress root folder.

chown -R YOUR_USER:YOUR_GROUP /WORDPRESS_ROOT/*

If you only want to change ownership of the plugins folder, run the command below:

chown YOUR_USER:YOUR_GROUP /WORDPRESS_ROOT/wp-content/plugins

Step 3 – Return to the root folder of WordPress and change the permissions of all folders and files using the command below:

find . -type d -exec chmod 755 {} \; && find . -type f -exec chmod 644 {} \;

Conclusion

It’s not that hard, right? WordPress is designed to be a shielded tool for certain situations and with a little analysis, the tool shows you exactly what is happening and how to fix it. From now on, you will be able to solve the problem whenever WordPress asks for FTP credentials.

If you are unable to fix the problem yourself, feel free to comment below and we will be more than happy to help you find a solution.

The 4-Step Framework To Successfully Scale a Care Plan Program