• When using wp-cli it seems that there are permission problems when (eg) installing plugins. The Linux system needs permission to create the new plugin directory and (I think) the WordPress system needs permission to install the plugin. The error/warning that comes back is: “Warning: Could not create directory.”

    What is the proper way to invoke this tool in such a way as to avoid this error?

    Here’s what I had to do to get wp-cli to work for me :
    1. Make sure the directories are all owned by www-data
    2. Make sure www-data is in /etc/sudoers (not sure if this is a security problem)
    3. Create a password for www-data group with “sudo passwd www-data”
    4. Invoke “wp” (or the script containing it) with: “sudo -u www-data …”
    5. Add this option to the “wp” command: –user=<username>

    …but I assume there is a more straightforward way.

    Please advise. Thanks in advance for the help

    • This topic was modified 5 years, 4 months ago by Marius L. J..
    • This topic was modified 3 years, 2 months ago by Jan Dembowski.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator Steven Stern (sterndata)

    (@sterndata)

    Volunteer Forum Moderator

    Generally, my sites run under an id which does not have a command shell (e.g., “wwwdev”), so I’ll do something like:

    su -
    su -s /bin/bash wwwdev
    cd /path/to/wordpress
    /usr/local/bin/wp (stuff)

    I start with su - because I don’t know the passwords for the restricted IDs, but i do know the password for root. /usr/local/bin/wp is a soft link to /usr/local/bin/wp-cli.phar

    Moderator Steven Stern (sterndata)

    (@sterndata)

    Volunteer Forum Moderator

    I accidentally tried to run wp-cli as root today and got this, which contains the solution to the question!

    Error: YIKES! It looks like you’re running this as root. You probably meant to run this as the user that your WordPress install exists under.

    If you REALLY mean to run this as root, we won’t stop you, but just bear in mind that any code on this site will then have full control of your server, making it quite DANGEROUS.

    If you’d like to continue as root, please run this again, adding this flag: –allow-root

    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>

    Thread Starter patrick_here

    (@patrick_here)

    Yes, I think that what’s needed is a better explanation of what happens when we use the “-i” option (followed by two hyphens) to “sudo”. The error message recommends this:

    sudo -u USER -i -- wp <command>

    …So the message implies that USER must be a defined user in the WordPress Site but I’m not clear on whether USER needs to be a defined user on the Linux Host also. Of course it’s possible to have a username on the Linux Host that matches the WordPress Site Username. However I was actually running this in a script performing identical operations on eight different wordpress installations (located on the same server) so for this to work they would all need to have one identical username. That’s do-able of course.

    I’ll probably try this out shortly …would still be interested to hear input from anyone else who tries it.

    Also: I have noticed that apparently it might not be necessary in any case to have the user in the /etc/sudoers file after all.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘wp-cli : Permissions issue (on Linux/Ubuntu)’ is closed to new replies.