Why a Fresh Install of WordPress Asks for FTP Server Info to Install Plugins

Ever manually install WordPress only to find that you can’t install or delete Plugins? There’s a common mistake that’s easy to make that causes this. 

Once you’ve uploaded all of your files to the Apache server it’s easy to forget to assign correct permissions to those files, so when you try to install a new Plugin you’ll get an error to the effect of “failed to connect to FTP server,” and no matter what server name, username, password, etc. you enter in the screen that appears, nothing works. Before freaking out, be sure your permissions are set correctly. To do this, log on to the Apache server and, assuming all of your web files are in/below the “html” directory, go up a directory and type:

chown www-data:www-data -R html

(You may need to preface it with “sudo” if permission is denied.)

That tells Linux to change ownership of the files & directories in the html directory (-Recursively) to the user www-data and the group www-data. This works because www-data is the user that WordPress is using when it’s accessing the server. If www-data doesn’t have rights to the directory structure, WordPress will attempt to write to the web server and fail, thereby falling back to a prompt to enter FTP credentials. As with most computer problems, this error doesn’t actually tell you what’s causing the problem….

(BTW, this is also true for Drupal, and other CMSs too!)

Steve