WP-CLI or WordPress Command Line Interface is a suite of commands that can make quick work out of updating plugins, setting up multisites, and much more WordPress management tasks, right from the Command Line Interface (CLI).
Install WordPress WP-CLI
- SSH into your server as the root user.
- You will need to download wp-cli.phar using either wget or curl.
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
NOTE: Using wget, if you get an error about the SSL certificate mis-match between www.github.com and raw.githubusercontent.com domains, you can skip the certificate check to download the file with:
wget –no-check-certificate https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
- Then test WP-CLI directly with PHP with this command:
php wp-cli.phar –info
You should see output similar to:
PHP binary: /opt/cpanel/ea-php70/root/usr/bin/php PHP version: 7.0.26 php.ini used: /opt/cpanel/ea-php70/root/etc/php.ini WP-CLI root dir: phar://wp-cli.phar WP-CLI packages dir: WP-CLI global config: WP-CLI project config: WP-CLI version: 0.24.1
- Next you’ll need to make the WP-CLI file executable and move it to your path:
chmod +x wp-cli.phar
mv wp-cli.phar /usr/local/bin/wp
- Now you can simply use wp at the command line to access WP-CLI:
Setup Bash Tab-to-Complete for WP-CLI
A great time saving feature of command line interfaces is using tab completion to quickly type in commands. You can add the ability to use tab completion for WP-CLI by setting it up in your local ~/.bash_profile file.
- SSH into your server as the user that will be using WP-CLI.
- Download the WP-CLI tab completion file to your server.
curl -O https://raw.githubusercontent.com/wp-cli/wp-cli/master/utils/wp-completion.bash
wget https://raw.githubusercontent.com/wp-cli/wp-cli/master/utils/wp-completion.bashNOTE: While using wget, if you get an error about the SSL certificate mis-match between www.github.com and raw.githubusercontent.com domains, you can skip the certificate check to download the file with:
wget –no-check-certificate https://raw.githubusercontent.com/wp-cli/wp-cli/master/utils/wp-completion.bash
- Move the WP-CLI tab completion file to your home directory:
mv wp-completion.bash ~/
- Now edit your ~/.bash_profile file to include the WP-CLI tab completion file:
- Add this line to the bottom of your ~/.bash_profile file:
Now save this file
- Back at the command line, make sure to source your ~/.bash_profile file by running this command:
- Now just type wp at the prompt, and hit Tab twice to see all the tab completions you just setup:
[email protected] [/home/exampl3/public_html]# wp cache comment eval help menu plugin role shell super-admin transient cap core eval-file import network post scaffold sidebar term user cli db export media option rewrite search-replace site theme widget
Now that you have installed WP-CLI you can begin using the command line to manage your WordPress website(s).
Learn more about WP-CLI, the command-line interface for WordPress, and streamline your WordPress maintenance workflow!