Fix: To Perform 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.

You are going to see:

Perform the requested action error Perform the requested action error

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

Top ↑

Solve the Access Issue Solve the Access Issue

We have a couple of ways to fix it.

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

Solution 1: Adding FS_METHOD Constant in wp-config.php file Solution 1: Adding FS_METHOD Constant in wp-config.php file

Follow the below steps:

  • Step 1: Go to your WordPress website installation root directory
  • Step 2: Find and open the wp-config.php file
  • Step 3: Add the below code into the file:
define( 'FS_METHOD', 'direct' );

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

Other File System APIs in WordPress Other File System APIs in WordPress

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

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, which 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 – Executing the sudo Commands Solution 2 – Executing the sudo Commands

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

Leave a Reply