I don't think this is a duplicate, although I've seen similar questions on here.
I have added my primary SSH/FTP user and the user
nobody to a group called
webserver, then I ran a
chown -R .webserver /var/www so that both FTP and Apache would be able to write to the file system.
I know that PHP can write to the server -- I can upload an image using the Media Library. However, when I go to install a plugin, it prompts me for my FTP credentials.
If I add
define('FS_METHOD', 'direct'); to wp-config.php, this goes away and plugins install without an issue.
Why would this happen, though? According to the Codex, the preferred method is direct, and it's able to manipulate the file system directly. So what would make it prompt for FTP instead?
I took a look at the source for how it determines what file system method to use (
wp-admin/includes/file.php, line 933), and I figured out that it can create a test file, but the owner does not match the processor's UID. Taking a look at the PHP manual for
fileowner($file), it seems that, instead of using
getmyuid(), it should be using
posix_getuid(). Any idea why the developers would use the former?
Noted in WordPress bug tracker: https://core.trac.wordpress.org/ticket/10205