I had an instance where every time I tried to add either a theme or plugin to my fresh WordPress install, WordPress would respond with something along the lines of “To perform the requested action, WordPress needs to access your web server”, followed by a form asking me to enter all the server’s FTP details.
It is not an issue that I usually encounter, and some quick Internet delving provided the answer – essentially WordPress was figuring out as to whether or not it had access to the filesystem, and if it didn’t, well then it would try and accomplish what it needs to do via FTP.
With that knowledge now gleaned, it made perfect sense – in this particular case I had only opened up the wp-content folder for writing, meaning that WordPress was technically blocked from writing to the filesystem anywhere other than that specific folder.
To solve this is relatively simple. If you have SSH root access to the Ubuntu server, then it is simply a matter of logging in and changing the ownership of the entire WordPress directory. So for example, if Apache is running as www-data, you could accomplish the ownership change via:
chown -R www-data: /home/www/wordpressdirectory
That should resolve the issue outright. (Note that not all versions of chown are equal. If that command does not work, see your local chown man page for usage information.)
Well, the above certainly solved my issue.
Bonus: A handy tip if you aren’t sure what user you instance of Apache is running as, create a test script with the following content:
<?php echo(exec("whoami")); ?>