How to Install WP-CLI on a linux
WP-CLI will be particularly useful if you are a WordPress developer, System Administrator or run a business built on WordPress. WP-CLI is an awesome command line tool for WordPress. It has a lot of commands that can help us installing plugins/themes, add posts, updating WordPress Core, taking backups, querying databases, import/export data quickly and easily. This command line tool will greatly help you do more in less time.
First Connect your server through SSH. wp-cli.org recommended to install WP-CLI is by downloading the Phar file. The latest version WP-CLI installation file is available here. You can download by using wget or curl. For Example:
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
Check if it works
Enter the following command to check if it works or not.
php wp-cli.phar --info
Creating executable files
Enter the following command to make it executable.
chmod +x wp-cli.phar
Move WP-CLI.PHAR File
We can move wp-cli.phar file to /usr/local/bin and rename it to wp. This will help us use the WP-CLI commands by just typing ‘wp’ at the start of the commands. Type wp –info to check the status.
sudo mv wp-cli.phar /usr/local/bin/wp
In future, you can update wp cli by entering the following command to update.
sudo wp cli update
For more information about wp-cli installation click here.
wp-cli bash completion
The bash completion feature of WP-CLI allows you to see all the available commands on the fly.
Download the bash script in your home directory:
cd ~/ wget https://github.com/wp-cli/wp-cli/raw/master/utils/wp-completion.bash
Edit the .bashrc file
Edit the file
.bashrc so that it is loaded by the shell every time you log in. Open the file and add the following line in the editor:
Run the following command to reload the bash profile:
That’s it. Bash completion is now enabled. To test it, type wp theme (include the trailing space) and press Tab twice. You will see the list of available commands with wp theme again on the prompt.