WP-CLI support to all users on server

Category : WordPress

To add support of the fantastic tool wp-cli for all the users on the server, be it cyberpanel or cPanel or some other webhost panel you are using, you can use the following solution :

Single Line code :

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;

Step by step breakup :

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

 

You would need to run this via root login of the server and this will make wp tool available for rest other users too.

To verify the installation, you can run the following command from user ssh login or root :

wp –version

It will display some information as per your system installation. If you get an error – wp command not found then probably your installation went wrong somehow.

You can check out some WP CLI usage here : https://www.basezap.com/install-wp-cli-install-wordpress-export-import-database-using-wp-cli/