In this tutorial:
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
or
wget 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:
wp –info
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
or
wget https://raw.githubusercontent.com/wp-cli/wp-cli/master/utils/wp-completion.bash
NOTE: 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:
vi ~/.bash_profile
- Add this line to the bottom of your ~/.bash_profile file:
source ~/wp-completion.bash
Now save this file
- Back at the command line, make sure to source your ~/.bash_profile file by running this command:
source ~/.bash_profile
- Now just type wp at the prompt, and hit Tab twice to see all the tab completions you just setup:
exampl3@server [/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 how to streamline your WordPress maintenance workflows!
I’m getting a total diff output when doing:
$php wp-cli.phar –info
dyld: Library not loaded: /usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib
Referenced from: /usr/local/bin/php
Reason: image not found
Abort trap: 6
…going to try locating the issue
Hello and thanks for contacting us. I recommend you check your bash history with the “history” command to ensure you followed the steps correctly. You may learn more from error logs as well.
This is great. Never knew it existed. Is there any compelling reason NOT to put “wp plugin update –all” into a cron job to run daily?
I would not recommend updating plugins daily. The problem exists in conflicts and upgrades. You want to be able to upgrade the plugins and immediately test to ensure everything in functioning properly. Also, prior to upgrading it’s bests practices to backup your site. That way if anything goes wrong in the upgrade, you can restore it accordingly. It really comes down to personal preferences.
Managing multiple WordPress websites is a hectic job, as you have to logging to each site and setup/install plugins and settings for each site independently.
Luckily for those well versed to work in command line, they can use WP-CLI to manage multiple WordPress sites with just a few commands. WP-CLI comes with built-in commands specific just to manage WordPress websites.
Through WP-CLI you can install, manage plugins and themes. Control settings such as cron-job, comments etc.
Hello Robert,
It seems like GitHub is using the SSL certificate for www.github.com also on their raw.githubusercontent.com domain, and wget is seeing this mis-match and warning you much like a web-browser would.
You can bypass this in wget as the error message says by using –no-check-certificate:
wget –no-check-certificate https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
Or you could also use curl which doesn’t check the certificate in this way:
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
Please let us know if you’re still having any issues, and thanks for letting us know about this problem so we can update this guide.
– Jacob