When you try to install the plugin in wordpress site it asks for FTP credentials

WordPress asks for FTP credentials when you install a plugin

Post Date: December 5, 2020
Last Updated: November 20, 2026

Introduction

This guide explains how to fix the problem when WordPress asks for FTP credentials while you install a plugin or update a theme. WordPress shows the FTP form when it cannot write to its own folders. The real fix is usually a file ownership change, not an FTP account.

The original guide told you to add FS_METHOD to wp-config.php and run chmod -R go+w wordpress. The second command makes every file writable by the group and by all other users, which is a security risk. This version fixes the ownership instead, keeps FS_METHOD as a fallback, and adds checks, exact error messages and troubleshooting.

Warning: If WordPress asks for FTP credentials, don’t get past it with chmod 777 or chmod -R go+w. Writable files let a compromised plugin, or another account on the server, change your site. Back up wp-config.php and your site files first.

Prerequisites

Before you fix the screen where WordPress asks for FTP credentials, make sure you have:

  • SSH access with sudo privileges
  • The path of the WordPress folder, for example /var/www/html/wordpress
  • A WordPress administrator login to test the install
  • A backup of wp-config.php and your site files
  • Knowledge of the user your web server runs as (Step 1 shows how to find it)

Architecture

  • WordPress writes a temporary file inside wp-content to test whether it can change files directly
  • It compares the owner of that file with the user that runs PHP (Apache, or PHP-FPM with Nginx)
  • If both are the same user, WordPress uses direct file access and installs plugins without asking
  • If the owners differ, WordPress falls back to FTP and shows the form
  • The FS_METHOD constant in wp-config.php skips that test, while correct ownership makes the test pass on its own

The image below shows the check. For the official references, see the WordPress developer guide to editing wp-config.php and the guide to file permissions.

Steps When WordPress Asks for FTP Credentials

1. Find the Web Server User

ps aux | grep -E 'apache2|httpd|nginx|php-fpm' | grep -v root | head -5

The user is usually www-data on Debian and Ubuntu, apache on RHEL-based systems, and nginx for some Nginx setups. On cPanel or Plesk servers, PHP often runs as the account user, so use that account name.

2. Back Up and Undo Unsafe Permissions

cd /var/www/html/wordpress
sudo cp wp-config.php wp-config.php.bak

If you already ran chmod -R go+w from the old guide, remove that permission:

sudo chmod -R go-w /var/www/html/wordpress

3. Set the Correct Ownership and Permissions

This is the main fix when WordPress asks for FTP credentials. Replace www-data with the user from Step 1:

sudo chown -R www-data:www-data /var/www/html/wordpress
sudo find /var/www/html/wordpress -type d -exec chmod 755 {} \;
sudo find /var/www/html/wordpress -type f -exec chmod 644 {} \;
sudo chmod 640 /var/www/html/wordpress/wp-config.php

Now open Plugins, then Add New, and try the install again. In most cases the FTP form is gone.

4. Add FS_METHOD Only If the Form Still Appears

Open wp-config.php and add this line above the comment that says “That’s all, stop editing!”:

define( 'FS_METHOD', 'direct' );

The original guide placed it after DB_COLLATE, which also works, as long as it comes before that comment. Type the quotes by hand or copy them from the code block. Curly quotes copied from a web page break PHP.

Note: FS_METHOD only tells WordPress to skip the ownership test. If PHP still can’t write to the folders, the install fails with “Could not create directory”, so Step 3 is still needed.

5. Test and Verify

Install a plugin and confirm that no FTP form appears. You can also check write access from the terminal:

ls -ld /var/www/html/wordpress/wp-content/plugins
sudo -u www-data touch /var/www/html/wordpress/wp-content/plugins/test.tmp && echo writable
sudo rm /var/www/html/wordpress/wp-content/plugins/test.tmp

In the dashboard, Tools, Site Health, Info, Filesystem Permissions shows which folders WordPress can write to.

Troubleshooting

If WordPress still asks for FTP credentials after the fix, check these:

  • “To perform the requested action, WordPress needs to access your web server. Please enter your FTP credentials to proceed.”: The folder owner and the PHP user still differ. Repeat Steps 1 and 3 with the correct user
  • “Installation failed: Could not create directory.”: wp-content or uploads is not writable. Check ownership, free disk space with df -h, and the SELinux note below
  • WordPress still asks for FTP credentials after you change the owner: PHP-FPM may run under a different user than the web server. Check the user = line in your PHP-FPM pool file, and use that user in Step 3
  • A “Parse error: syntax error” page after editing wp-config.php: The edit has curly quotes or a missing semicolon. Restore wp-config.php.bak and add the line again
  • “Unable to locate WordPress Content directory (wp-content).”: WordPress is trying FTP with wrong details. Fix the ownership instead of entering FTP details
  • SELinux blocks writes on RHEL-based systems: Set a writable context on wp-content, then restore it:
sudo semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/html/wordpress/wp-content(/.*)?"
sudo restorecon -R /var/www/html/wordpress/wp-content

Conclusion

When WordPress asks for FTP credentials, the cause is almost always a mismatch between the file owner and the PHP user. Find the web server user, set it as the owner, use 755 for folders and 644 for files, and add FS_METHOD only if the form persists. Avoid chmod 777 and go+w, since they fix the symptom by weakening your site’s security.

Frequently Asked Questions (FAQs)

Why does my site show a screen that asks for FTP credentials?
WordPress could not write a test file as the user that runs PHP. When the file owner and the PHP user differ, it assumes it needs FTP to change files.

Is define( 'FS_METHOD', 'direct' ); safe?
It is safe when the ownership is already correct, because it only skips the check. It does not grant write access, so it will not fix a permission problem by itself.

Should I use chmod 777 or chmod -R go+w instead?
No. Both let other users on the server modify your files. Use chown with 755 for folders and 644 for files.

Do I need an FTP account for plugin installs?
Not on a server where you control ownership. Direct file access works once the file owner matches the PHP user.

How to Block IPs via .htaccess File

How to Add a New Domain in the DirectAdmin Panel

Talk to Our Technology Experts

Worried about insecure file permissions on your WordPress server? Our team can correct ownership, lock down write access, and harden your hosting environment through our Security Services.

Connect with our technology experts.

admin

Our team has expertise across software and web development, WordPress, e-commerce, mobile applications, UI/UX, cloud and infrastructure, DevOps, CI/CD, API integration, security, testing, automation, and technical support. The team also works with AI-based software solutions, LLMs, AI workflows, AI agents, and intelligent application development to help businesses automate processes and build smarter digital solutions. We focus on developing, deploying, maintaining, and optimising secure, scalable, and reliable technology solutions while helping businesses adopt modern technologies and drive digital transformation.

Leave a Comment

Scroll to Top