Search code examples
wordpressapachevirtualhostmod-userdir

How to Write/Upload from Wordpress Web Interface Installed on Ubuntu 18.04 VirtualBox


Host: Windows 10 64bit

VirtualBox: Ubuntu 18.04 Apache 2.4, MySQL 5.7.25, PHP 7.2.10 userdir module enabled

I've installed WordPress thus:

chris@montford:~/public_html$ wp core download
Downloading WordPress 5.0.3 (en_US)...
md5 hash verified: 83bec78836aabac08f769d50f1bffe5d
Success: WordPress downloaded.

When I go to /localhost/~chris/ in Chromium, I get the standard install web page. I fill in the standard setup form, but always get "Sorry, but I can't write the wp-config.php file. You can create the wp-config.php manually..."

I could follow these directions, but it basically means that I can't write files from the wordpress browser interface on my dev site. It also means I can't upload photos or docs or add plugins and themes via the standard WordPress web interface even if I did configure wp-config.php manually.

There is likely a security protocol in place that keeps me from allowing the web server to upload/edit/change files, even though userdir is enabled. From what I could understand, this isn't covered in the "Apache Module mod_userdir" web page, nor in its accompanying "Per-user web directories" page.

This would be the case whether it was WordPress or some other CMS. Directories are all at the standard 755. I shouldn't have to set any directory to 777.

I'd rather not use the FTP method, and I'd like to see my files uploaded/added from the WordPress web interface as user:group chris:chris rather than something like www-data:www-data.

What steps must I follow to allow WordPress to behave as expected on a normal host box so that it can automatically create its own wp-config.php file, and add themes and plugins directly from the web interface?


Solution

  • By default, apache runs as user www-data. Your files are set as 755 and chris is the owner. This means, chris can run, edit and execute the files (7), other users can only read and execute them, but not change (5). So Apache can't change the files.

    You can now either

    1. change apache to run as user chris
    2. change the files to allow www-data to write them (777)
    3. change ownership to www-data and use www-data user to edit/upload the files
    4. change ownership to www-data and add user chris to the www-data user group
    5. change the owner of the whole wp directory to www-data:www-data once (chown -R www-data:www-data /var/www/yoursite [or /home/chris/public/... in your case]) and then create the directories you need to edit under your account (most likely anything like /wp-content/plugins/yourplugin or /wp-content/themes/yourtheme). Or set the owner for them to chris if they have already been created.

    Most likely, 5. will work fine as wordpress only needs read access to your custom plugins and themes, and you don't need to edit anything outside of these. I don't recommend any of the other options really, just listed them so you get the picture.