4

I've followed the instructions provided on the wp-cli.org site but I can't seem to get the wp command to run for all users.

I copied the file to /usr/local/bin and renamed it to wp per the instructions. And when I'm logged in as root I can run wp from anywhere and it works (although it gives me the "are you sure you want to run this as root?" warning).

I was under the impression that moving an executable to /usr/local/bin would make that executable available to all users. However, when I switch to another user, I get a "command not found" error.

How can I install wp-cli for all users? I want to make sure every user with SSH access can run wp-cli.

Thanks in advance!

Ian Svoboda
  • 51
  • 1
  • 5
  • You need to add `/usr/local/bin` to the `PATH` globally. – chicks Mar 20 '17 at 02:17
  • This is actually in the global user PATH. When I login as a non-root user and run echo $PATH this is what I get: ```/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/opt/cpanel/composer/bin:/home/iansvoboda/.local/bin:/home/iansvoboda/bin``` The problem is that the binary ```wp``` isn't present in ```/usr/local/bin``` for non-root users. Also, I'm running WHM, so I suppose there could be some security restriction or something on 3rd party binaries? – Ian Svoboda Mar 20 '17 at 02:38
  • What do you get if you run `/usr/local/bin/wp`? – chicks Mar 20 '17 at 02:41
  • ```-bash: /usr/local/bin/wp: No such file or directory``` This is what I would expect, since as I said the binary doesn't appear to be present in that directory for a non-root user. I have no idea why though. – Ian Svoboda Mar 20 '17 at 02:44
  • I would expect `/usr/local/bin/` to be the same for everybody. But that command works for you as `root`? – chicks Mar 20 '17 at 02:46
  • Yes it does. The contents of that directory as root do not much the contents of non-root users. I'm thinking that perhaps the other binaries in that directory are hidden from non-root users by default or something. But I'm not having much luck turning up a solution yet – Ian Svoboda Mar 20 '17 at 02:57
  • Does www-data own the file? Any reason to not have users use sudo to use wp-cli? That would still meet your requirement for SSH users to access it. – Mountainerd Mar 20 '17 at 04:15
  • File owner is root. As far as sudo goes, I guess I thought that was only something a root user would run? – Ian Svoboda Mar 20 '17 at 04:16

2 Answers2

1

I determined that the issue was related to cageFS.

Solution

If the server environment is using CloudLinux with cageFS enabled, cageFS definitions must be updated to allow the wp command to be accessible to non-root users

I found these instructions here to do this: https://docs.redy.host/knowledge-base/install-wp-cli-cpanel-cagefs/

gregdev
  • 103
  • 4
Ian Svoboda
  • 51
  • 1
  • 5
0

Generic solution is to install WP-CLI as the root user, typically putting it in /usr/local/bin:

Step 1

curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar

Step 2

chmod +x wp-cli.phar

Step 3

sudo mv wp-cli.phar /usr/local/bin/wp

Now add /usr/local/bin to the $PATH of each user which can either be done locally for each user by adding PATH=$PATH:/usr/local/bin into the ~/.bashrc or ~/.bash_profile or, even cooler, but adding that path globally from the root user by putting the PATH export in a bash script within /etc/profile.d/. For example:

Step 4

# /etc/profile.d/add_user_local_bin.sh
PATH=$PATH:/usr/local/bin

Now all the users can use wp-cli commands. Cool.

MikeiLL
  • 247
  • 1
  • 4
  • 10