Banzai
By:
Banzai

WordPress & plugins can't write files or create directories.

November 20, 2014 10.4k views

I have a Ubuntu droplet with LAMP installed at setup and I need to host a few different sites & domains there, so the first site's path is /var/www/sitename.com/public_html, as opposed to the single-install WordPress setup. I also set up phpMyAdmin according to the DO tutorial, then set up the WordPress user and db, and imported the data. Then I copied the WordPress site up and unzipped it in place. At this point the admin and front end work except when needing to write a file or create a directory.

I then followed this tutorial -- https://www.digitalocean.com/community/tutorials/how-to-configure-secure-updates-and-installations-in-wordpress-on-ubuntu -- to the letter and didn't hit any snags. It's still unable to write to files or create directories, though. The admin looks fine but my front-end is completely unstyled because it's dependent on a LESS plugin that needs to write newly compiled CSS files.

I'm a little lost at this point because I don't know what else to do beyond setting ownership to wp-user:wp-user and making sure the permissions are set to the correct levels according to the Digital Ocean tutorial. Any ideas?

Thanks!

3 comments
  • In your wp-config.php file, what is the setting for FS_METHOD It should be:

    define('FS_METHOD', 'ssh2');
    
  • That setting wasn't in the wp-config.php file so I added it but WordPress still can't write & asks for FTP login info.

  • Sorry about the two unintended answers I posted below. I typed my comment in the wrong box.

4 Answers

Why not stick with the default permissions?

chown www-data:www-data /var/www/sitename.com/public_html
  • Because that's not what the tutorial said to do. Do you have a suggestion or is your question an answer?

  • that's not what the tutorial said to do

    That's not a problem, if you are the only one managing the site and the Droplet it can be set to www-data. I have it set that way and it doesn't need any extra settings to install plugins/themes.

  • I don't have a www-data user, do I?

  • I don't have a www-data user, do I?

    Of course it is there on all LAMP setups on Ubuntu.

    You can verify it:

    grep www-data /etc/passwd
    
  • So I'll need to change these lines again?:

    define('FTP_PUBKEY','/home/wp-user/wp_rsa.pub');
    define('FTP_PRIKEY','/home/wp-user/wp_rsa');
    define('FTP_USER','wp-user');
    define('FTP_PASS','');
    define('FTP_HOST','127.0.0.1:22');
    
  • Not required, just don't add them to your wp-config.php file.

    When the files/directories are owned by www-data PHP will be able to write them without the need for FTP.

  • Okay I commented out those lines and plugins still couldn't write, until I realized that I needed to run that chown command recursively. When I did that, it started working. Thanks for your help!

  • Oops I missed the -R option.

    You're welcome!

Have you added the following lines to wp-config.php?

define('FTP_PUBKEY','/home/wp-user/wp_rsa.pub');
define('FTP_PRIKEY','/home/wp-user/wp_rsa');
define('FTP_USER','wp-user');
define('FTP_PASS','');
define('FTP_HOST','127.0.0.1:22');

Make sure that the paths are correct. The files should look something like this:

-----BEGIN RSA PRIVATE KEY-----
...
-----END RSA PRIVATE KEY-----
ssh-rsa ... kamal@iodine

If they're correct but it's still not working, try SSHing in manually:

ssh -i /home/wp-user/wp_rsa wp-user@localhost

Does that work?

  • The files look right but when attempt to log in it asks for wp-user's password. It doesn't have a password, though, and I get an error when I submit a blank password.

Have another answer? Share your knowledge.