27

I succesfully set up a VPS LEMP-stack with Wordpress. When I am trying to install plugins from the WP backend, I am prompted with the following message:

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

When I enter my SFTP-account details, which I am using to access the server with FileZilla, I get the following error message:

Failed to connect to FTP Server 192.XXX.XXX.X:21

I read various tutorials, which suggest to install a FTP server, in particular vsftpd and then to store your FTP-User-details in the wp-config.php to avoid further authentication requestst. The problem I see is that, FTP is considered as severly unsecure and I would like to avoid hard-coding my user details into my WP-installation.

What is the safest, recommended way to deal with this problem?

  • 1
    You wouldn't get the FTP message if you had write permissions set on your plugins folders in wp-content – Jeff Wooden Jan 23 '14 at 18:24
  • 6
    @JefferyAWooden The following seems to solve my issue: `sudo adduser www-data sudo chown -R www-data:www-data /var/www sudo chmod -R g+rw /var/www` –  Jan 23 '14 at 18:43
  • 1
    @user3046831 Thanks your post solved my same problem. – Maykel Llanes Garcia Jan 21 '15 at 21:50
  • possible duplicate of [Can I install/update WordPress plugins without providing FTP access?](http://stackoverflow.com/questions/640409/can-i-install-update-wordpress-plugins-without-providing-ftp-access) – kuldipem May 12 '15 at 18:33

10 Answers10

71

I don't know if it is the safest method or not. But pasting this code in wp-config.php once solved my problem:

define('FS_METHOD', 'direct');
Omar Tariq
  • 7,536
  • 10
  • 38
  • 57
  • 2
    This method fixed the issue for me. However I also had to change the permissions of my themes folder so it could then create the required directories. – CodyEngel Nov 01 '14 at 22:54
  • 1
    OP didn't pick it as correct answer. Wishes do not come true in this life T_T – Omar Tariq May 15 '16 at 08:12
  • 1
    This is effective, but it comes with security problems. This is mentioned briefly in [the documentation at codex](https://codex.wordpress.org/Editing_wp-config.php#WordPress_Upgrade_Constants), but unfortunately dumps you on another StackExchange site for [a detailed answer](http://wordpress.stackexchange.com/questions/189554/what-security-concerns-should-i-have-when-setting-fs-method-to-direct-in-wp-co) – Vince May 14 '19 at 12:43
  • According to "all the best" documentation it says to use "define('FS_METHOD', 'ssh2');" but after several hours of debug I found this comment and 'direct' worked for me. And it IS case sensitive. – Jimbo Jun 17 '21 at 15:21
31
sudo chown -R www-data:www-data wp_site_root
sudo chmod -R g+rw wp_site_root

solved my problem.

kuldipem
  • 1,719
  • 1
  • 19
  • 32
7

Remember to set files and directories permission in this way:

chown -R www-data:www-data /var/www
find /var/www/ -type d -exec chmod 755 {} \;
find /var/www/ -type f -exec chmod 644 {} \;
Flavio Troia
  • 2,451
  • 1
  • 25
  • 27
4

define('FS_METHOD', 'direct');

adding the above given command on the wp-config file will resolve that issue paste it below

define( 'WP_DEBUG', false );

naran g
  • 51
  • 3
2

@MrNerdy,

I should have also elaborated on the fact that there should be some other folders you'll want to give permissions to. Read the documentation on it here to understand exactly what you should do regarding security: http://codex.wordpress.org/Changing_File_Permissions

Also, be careful to only install trusted plugins. I've seen dozens of sites hacked because of badly coded plugins / themes, etc. Good luck.

Jeff Wooden
  • 5,339
  • 2
  • 19
  • 24
2

For me it was bitnami related settings issue. This post helped me. There could be multiple reason:

  • Permission issue on the files and folders.
  • The FS_METHOD should be "direct" in wp-config.php file.
  • Remove FTP configuration from wp-config.php if you are migrating from bitnami to manage it on your own.
drishti ahuja
  • 1,379
  • 2
  • 15
  • 26
1

If anyone is running into this issue using MAMP Pro.

Make sure you're running the server as the user that has permission for the root wordpress directory.

Under SETTINGS > Ports look for "Run server as" and in the drop down choose the same system user that has permission to access the root wp folder.

enter image description here

hitautodestruct
  • 20,081
  • 13
  • 69
  • 93
1

its just a permisson error sudo chown -R www-data:www-data your wordpress site root folder sudo chmod -R g+rw wordpress site root folder

0

Add this line to wp-config.php:

define('FS_METHOD', 'direct');

Then change the permission If you're using an ec2 instance.

cd /var/www/html/wordpress
James Risner
  • 5,451
  • 11
  • 25
  • 47
ShivamH
  • 11
  • 3
-1

if your'e using shared hosting then remove some files in your server and try again. it will work. its because your disk quota may be exceeded.