Operating System & Version
CentOS Linux release 7.9.2009
cPanel & WHM Version
92.06

mlopez

Well-Known Member
Dec 17, 2020
54
7
8
Maldonado - Uruguay
cPanel Access Level
Root Administrator
Twitter
Hello,

I've installed wp-cli using yum.

Now, when I try to execute a wp command as a cpanel user (being /home/some_user/public_html/ the :

Bash:
cd /home/some_user/public_html/
sudo -u some_user wp plugin list
I get the following error:

Bash:
PHP Warning:  Use of undefined constant STDOUT - assumed 'STDOUT' (this will throw an Error in a future version of PHP) in phar:///usr/bin/wp/vendor/wp-cli/wp-cli/php/utils.php on line 1057
PHP Warning:  Use of undefined constant STDERR - assumed 'STDERR' (this will throw an Error in a future version of PHP) in phar:///usr/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Loggers/Regular.php on line 50
PHP Warning:  fwrite() expects parameter 1 to be resource, string given in phar:///usr/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Loggers/Base.php on line 64
Content-type: text/html; charset=UTF-8
The only way I can issue a wp command is changing the user before, like this:
Bash:
cd /home/some_user/public_html/
su some_user
wp plugin list
exit
What should I do to allow wp to work with sudo?

Thanks in advance

Mauricio
 

cPRex

Jurassic Moderator
Staff member
Oct 19, 2014
7,519
1,028
313
cPanel Access Level
Root Administrator
Hey there! Can you try this simple one-liner to confirm that your sudo access in general is working properly for that user?

Code:
sudo -H -u otheruser bash -c 'echo "I am $USER, with uid $UID"'
Just replace the "otheruser" name with the actual username of the account you are working with to test this.
 

mlopez

Well-Known Member
Dec 17, 2020
54
7
8
Maldonado - Uruguay
cPanel Access Level
Root Administrator
Twitter
Thank you for your reply.

When I run this with an existing user I get:
Code:
I am theuser, with uid 1002
If I run it with a dummy user name I get:
Code:
sudo: unknown user: otheruser
sudo: unable to initialize policy plugin
 

cPRex

Jurassic Moderator
Staff member
Oct 19, 2014
7,519
1,028
313
cPanel Access Level
Root Administrator
That sounds correct to me - that's what I would expect to happen, and indicates the sudo access itself is working well.

When you did the initial wp-cli installation, was that work performed as root or as a cPanel user? It might be worth reading through the details listed here since you are running into odd behavior with that tool:

 

splaquet

Well-Known Member
Sep 24, 2008
53
3
58
W. Hartford, CT
cPanel Access Level
Root Administrator
Twitter
i do believe that the latest wp-cli release has conflicts with php7.4.

run this: (i'm exhausted, but i think this is it. it's the --nightly part that's important.)
wp cli update --nightly

that'll install the latest nightly build, which *is* 7.4 compatible.
 

mlopez

Well-Known Member
Dec 17, 2020
54
7
8
Maldonado - Uruguay
cPanel Access Level
Root Administrator
Twitter
i do believe that the latest wp-cli release has conflicts with php7.4.

run this: (i'm exhausted, but i think this is it. it's the --nightly part that's important.)
wp cli update --nightly

that'll install the latest nightly build, which *is* 7.4 compatible.
I've installed the nightly build, but it keeps showing me errors:

Code:
❯ sudo -i -u user wp info
PHP Warning:  Use of undefined constant STDOUT - assumed 'STDOUT' (this will throw an Error in a future version of PHP) in phar:///usr/bin/wp/vendor/wp-cli/wp-cli/php/utils.php on line 1057
PHP Warning:  Use of undefined constant STDERR - assumed 'STDERR' (this will throw an Error in a future version of PHP) in phar:///usr/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Loggers/Regular.php on line 41
PHP Warning:  fwrite() expects parameter 1 to be resource, string given in phar:///usr/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Loggers/Base.php on line 64
PHP Warning:  Use of undefined constant STDERR - assumed 'STDERR' (this will throw an Error in a future version of PHP) in phar:///usr/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Loggers/Regular.php on line 50
PHP Warning:  fwrite() expects parameter 1 to be resource, string given in phar:///usr/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Loggers/Base.php on line 64
Content-type: text/html; charset=UTF-8
I've found that php root's path differs from php user's path. See:

Code:
❯ sudo -i -u user php -v
PHP 7.4.15 (cgi-fcgi) (built: Feb 26 2021 12:25:40)
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.15, Copyright (c), by Zend Technologies
❯ php -v
PHP 7.4.15 (cli) (built: Feb 26 2021 12:25:36) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.15, Copyright (c), by Zend Technologies
So, user isn't using php-cli but php-fcgi. Could this be the problem?

How can I change to all users, php path? environment variable?

Regards,

Mauricio