• Resolved daviddumonde

    (@daviddumonde)


    So I’m getting my feet wet with WP-CLI, but I’m confused about root vs non-root user.

    If I’m using my non-root user, I don’t have privileges in /var/www/html/domain. If I sudo, WP-CLI throws a hissy fit about not using root.

    If I go to /var/www/html and mkdir domain, then domain is owned by root. If I go to /var/www/html/domain and ‘wp core download’, I get ‘Error: ‘/var/www/html/ask/’ is not writable by current user.’ It gives further reasons why running as root is a bad idea, instructions for doing it anyway, and then “If you’d like to run it as the user that this site is under, you can run the following to become the respective user: sudo -u USER -i — wp <command>”.

    So what user should I be using if I shouldn’t use root and I can’t use my own regular non-root user? Do I need to move my installs to my home folder? Or is there some other way to use WP-CLI in the normal /var/www/html/domain directories?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hi there David,

    Have you tried changing the ownership of the doc root (which I’m assuming is public_html) to www-data and adding your non-root user to that group?

    https://www.linode.com/docs/websites/cms/install-wordpress-using-wp-cli-on-ubuntu-14-04

    Main Install Section; Step 2

    Change the ownership of the public_html directory. Apache comes with its own usergroup www-data. As a recommended practice, you should change the ownership of your installation directory to this group. You also need to add your username to the group, and enable group write permissions to perform any commands in the directory:

     sudo chown -R www-data public_html
     sudo usermod -aG www-data username
     sudo chmod -R g+w public_html

    Also, this is normal for any command that is writing to the directory. You will want to use the prefix sudo -u when using commands such as ‘wp core download’ on environments set up in this way.

    Here is another similar issue where it was recommended to “add nonroot to the www-data group, and make your files group”readable/writable.”

    https://github.com/wp-cli/wp-cli/issues/1241

    Thread Starter daviddumonde

    (@daviddumonde)

    Thanks very much for the help, Coleman. It’s clear now what I was missing. I’d never picked up the habit of setting my nonroot as owner of my installs because I was simply able to sudo. I did have my nonroot added to www-data, but I didn’t think to set group write permissions on the html directory. I actually looked at the two articles you linked to, but with your help they make a lot more sense now. I’ve given it a spin and successfully completed and install with wp-cli. Thanks for your help! (And howdy from down the road in Houston!)

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘WP-CLI root vs non-root user’ is closed to new replies.