[Solve] To perform the requested action WordPress needs to access your web server

Advertisement

WordPress will prompt you for FTP credentials If it does not have permission to write the files it needs to.

Whenever this happens we can see the error:

To perform the requested action, WordPress needs to access your web server. Please enter your FTP information to continue. If you do not remember your information, contact your web host.

Like the below screenshot:

WordPress needs to access your web server
WordPress FTP Permission Popup

How to solve access to your web server? How to solve access to your web server?

We have a couple of ways to fix it.

See below a few different solutions and try which one best fits you.

Solution 1 Solution 1

Add the below code to your functions.php file.

define( 'FS_METHOD', 'direct' );

By default WordPress use class WP_Filesystem_Direct to handle the file system.

And after adding the above constant WordPress uses the class WP_Filesystem_Direct to directly handle the PHP file and folder manipulation.

The constant FS_METHOD forces the filesystem method.

We can use direct, ssh2, ftpext, or ftpsockets.

Basically, We should only change this if we have any issues with FTP.

Also, Prefer the below sequence while experimenting with the constant FS_METHOD.

  • 1st Preference – direct – forces it to use Direct File I/O requests from within PHP, this is fraught with opening up security issues on poorly configured hosts, This is chosen automatically when appropriate.
  • 2nd Preference – ssh2 is to force the usage of the SSH PHP Extension if installed
  • 3rd Preference – ftpext is to force the usage of the FTP PHP Extension for FTP Access, and finally
  • 4th Preference – ftpsockets utilizes the PHP Sockets Class for FTP Access.

See more about the file permissions.

define( 'FS_METHOD', 'ftpext' );
define( 'FTP_BASE', '/path/to/wordpress/' );
define( 'FTP_CONTENT_DIR', '/path/to/wordpress/wp-content/' );
define( 'FTP_PLUGIN_DIR ', '/path/to/wordpress/wp-content/plugins/' );
define( 'FTP_PUBKEY', '/home/username/.ssh/id_rsa.pub' );
define( 'FTP_PRIKEY', '/home/username/.ssh/id_rsa' );
define( 'FTP_USER', 'username' );
define( 'FTP_PASS', 'password' );
define( 'FTP_HOST', 'ftp.example.org' );
define( 'FTP_SSL', false );

Top ↑

Solution 2 Solution 2

If you have server administrator access then you can change the file permissions.

The command chown (an abbreviation of change owner).

for NGINX Servers:

sudo chown www-data:www-data -R /path/to/files

for Apache Servers:

sudo chown apache:apache -R /path/to/files

and change directory permissions

sudo chmod 755 -R /path/to/files

How to fix error: To perform the requested action WordPress needs to access your web server

%d bloggers like this: