Installing WP-CLI will help you install WordPress more quickly. It will also be immensely helpful for updating WordPress core, theme and plugins later.
Step 1 – Open your terminal
Windows
If you’re on a Windows computer, make your life easier and install Git BASH. It comes as part of Git for Windows. To open Git BASH, their instructions say this:
Once downloaded, find the included .exe file and open to execute Git Bash.
Mac or Linux
If you’re on Mac or Linux, open your Terminal.
Step 2 – Log in to your server
If you’re following this tutorial, you should already be logged in to your server (this page showed you how to log in.). If not, log in to your server with SSH:
(replace user
with your server’s username and IP
with your server’s IP address)
ssh user@IP
Step 3 – Install WP-CLI on Your Server
Change to your home directory:
cd
Download WP-CLI to your home directory:
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
Then, check if it works:
php wp-cli.phar --info
In the information that appears, the last line should display the version, like:
WP-CLI version: 2.11.0
Give WP-CLI executable permissions. This will allow WP-CLI to run on the server:
chmod +x wp-cli.phar
Move WP-CLI into your path so you can type commands with just wp
:
sudo mv wp-cli.phar /usr/local/bin/wp
Test the WP-CLI installation:
wp --info
You should see the version of WP-CLI that you installed, like:
WP-CLI version: 2.11.0
You’re finished installing WP-CLI. Now you can use it to install WordPress, update WordPress core, themes and plugins, and more.
Optional: Create a Script to Update WP-CLI
This is so that in the future, you can easily update WP-CLI.
Switch to your home directory:
cd
Create a new file called wpcli_update.sh
in your home directory, and open the file for editing:
nano wpcli_update.sh
Copy this to paste into the new wpcli_update.sh
file:
cd 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
Save your changes to the wpcli_update.sh
file:
CTRL + o, then Enter.
Exit from nano:
CTRL + x
Grant executable permissions to wpcli_update.sh
:
chmod +x wpcli_update.sh
You will not use this script yet. Whenever you want to update WP-CLI, you will run this script. This script will download the latest version of WP-CLI and replace the old version with the new one.
For Future Reference: How To Update WP-CLI With Your Script
When you want to update WP-CLI, first check if there’s an update:
Change to your site’s web root directory (replace site.com
with your own site’s directory):
cd /var/www/site.com/public_html/
Check if there is a WP-CLI update available:
wp cli check-update
If there is WP-CLI update available, update it using the script we created in your home directory:
Change to your home directory:
cd
Update WP-CLI:
./wpcli_update.sh
Note: You can check your current version of WP-CLI with wp --info
from your site’s public_html directory, like this:
(replace site.com
with your own site’s directory)
cd /var/www/site.com/public_html/
wp --info
Questions and Comments are Welcome