Add WP CLI globally for all users

If you haven’t heard of it the wp cli is amazing for resetting passwords managing plugins updates and so much more.

https://wp-cli.org/

Steps one by one.
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp
nano /etc/profile.d/add_user_local_bin.sh
PATH=$PATH:/usr/local/bin

Oneliner.
wget -O /usr/local/bin/wp https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar; chmod +x /usr/local/bin/wp; touch /etc/profile.d/add_user_local_bin.sh; echo ‘PATH=$PATH:/usr/local/bin’ >> /etc/profile.d/add_user_local_bin.sh;

How it looks.
root@ols:~# wget -O /usr/local/bin/wp https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar; chmod +x /usr/local/bin/wp; touch /etc/profile.d/add_user_local_bin.sh; echo ‘PATH=$PATH:/usr/local/bin’ >> /etc/profile.d/add_user_local_bin.sh;
–2019-10-09 23:36:44-- https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
Resolving raw.githubusercontent.com (raw.githubusercontent.com)… 151.101.0.133, 151.101.64.133, 151.101.128.133, …
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|151.101.0.133|:443… connected.
HTTP request sent, awaiting response… 200 OK
Length: 5542314 (5.3M) [application/octet-stream]
Saving to: ‘/usr/local/bin/wp’

/usr/local/bin/wp 100%[=============================================================================>] 5.29M 31.0MB/s in 0.2s

2019-10-09 23:36:45 (31.0 MB/s) - ‘/usr/local/bin/wp’ saved [5542314/5542314]

root@ols:~#

Then login as a user
su - user

Then you should be able to use wp CLI commands like.

[user@ols:~/public_html]$ wp core version
5.2.3
[user@ols:~/public_html]$ wp plugin list
±------------------------±---------±----------±--------+
| name | status | update | version |
±------------------------±---------±----------±--------+
| cmb2 | active | none | 2.6.0 |
| disable-comments | active | none | 1.10.2 |
| display-posts-shortcode | active | none | 3.0.2 |
| litespeed-cache | active | none | 2.9.8.6 |
| minify-html-markup | inactive | none | 1.99 |
| redux-framework | active | none | 3.6.15 |
| whattheserver-plugin | active | none | |
| sucuri-scanner | active | none | 1.8.21 |
| virtusky-core | active | none | 1.0 |
| w3-total-cache | inactive | none | 0.10.1 |
| wordfence | inactive | none | 7.4.0 |
| wp-geshi-highlight | active | none | 1.4.1 |
| js_composer | active | available | 5.6 |
| wordpress-seo | active | none | 12.2 |
| advanced-cache.php | dropin | none | |
±------------------------±---------±----------±--------+
[user@ols:~/public_html]$

Resources.

I would also like to add some info to this thread:

Type the following command to see all available users that can log into the system:

root@srv:~# getent passwd | egrep -v ‘/s?bin/(nologin|shutdown|sync|halt)’ | cut -d: -f1

Usually the last usernames are the users that is automatically created when we add a website.

It seems for me that inserting the correct php version at the begging of the PATH was the solution of my problem with this :
PATH=/usr/local/lsws/lsphp74/bin:$PATH
Otherwise I got error message that my version of PHP doesn’t support MySQL requested for wp-cli

it is important to add the exact location like you gave otherwise that will be the issue. in most caese user add the path from the article that is not right