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:
Struggling with downtime and WordPress problems? Kinsta is the hosting solution designed to save you time! Check out our features
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.
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, which is fraught with opening up security issues on poorly configured hosts, This is chosen automatically when appropriate.
- 2nd Preference –
ssh2is to force the usage of the SSH PHP Extension if installed
- 3rd Preference –
ftpextis to force the usage of the FTP PHP Extension for FTP Access, and finally
- 4th Preference –
ftpsocketsutilizes 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 );
Deploy your application to Kinsta – Start with a $20 Credit now. Deploy now and get $20 off
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