How to Install WordPress CLI globally

How to Install WordPress CLI globally

In this article we will go over how to install the WordPress WP CLI globally on a server for all users easily.

This is great if you just setup a new server and want to ensure all users can easily use the WP CLI without having to install it manually per user.

The below “one liner” wgets the wp cli to “/usr/local/bin/wp” and makes it executable. It then adds this folder to the global PATH for all users so they can use it via “wp” without aliases or typing the full path. This requires being done as the ROOT user.

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;

Once installed you can then logout or login into a user from root and then issue “wp –info” to see if its working properly.

Example:

wizardassistantrocks@server:~/public_html$ wp --info
OS:     Linux 5.4.0-52-generic #57-Ubuntu SMP Thu Oct 15 10:57:00 UTC 2020 x86_64
Shell:  /bin/bash
PHP binary:     /usr/bin/php7.4
PHP version:    7.3.22-1+focal
php.ini used:   /usr/local/lsws/lsphp73/etc/php/7.3/litespeed/php.ini
WP-CLI root dir:        phar://wp-cli.phar/vendor/wp-cli/wp-cli
WP-CLI vendor dir:      phar://wp-cli.phar/vendor
WP_CLI phar path:       /home/wizardassistant.com/public_html
WP-CLI packages dir:
WP-CLI global config:
WP-CLI project config:
WP-CLI version: 2.4.0
wizardassistantrocks@server:~/public_html$ which wp
/usr/local/bin/wp
wizardassistantrocks@server:~/public_html$

For information about the WP CLI checkout their official installation guide.

If installing on a CloudLinux server with CageFS you will also need to ensure you add it to the CageFS config and rebuild it for all users.

Create and edit the file via nano : /etc/cagefs/conf.d/wpcli.cfg

nano /etc/cagefs/conf.d/wpcli.cfg

Then add the below.

[wpcli]
comment=Allow wp-cli to work on the server
paths=/usr/local/bin/wp

Then rebuild CageFS for all users. I recommend running it in detached screen session as it can take a bit on a server with lots of users. This will fire it off in background so you can move onto other tasks without it getting interrupted.

screen -dmS cagefs_update bash -c 'cagefsctl --force-update ; exec sh' ;
Item added to cart.
0 items - $0.00