Guide on Using WP-CLI for Your WordPress Site

wordprss--5WP-CLI, short for WordPress Command Line Interface, is a set of command-line tool specifically designed for managing WordPress installations. Webmasters can use WP-CLI to update WordPress plugins, set up multisite installs and etc. without making use of a web browser.

In this guide, we are going to bring a comprehensive introduction of WP-CLI, including why use WP-CLI, how to install WP-CLI, and what you can use WP-CLI for.

Why Use WP-CLI

It is an undeniable fact that the WordPress admin interface is intuitive and easy-to-use, the natural question is: why do we have to use a command line interface?

However, on the one hand, using keyword is always faster than using the mouse. Especially when you plan to have some power uses, you will find that pressing buttons in a web browser is much slower than typing a command. On the other hand, WP-CLI allows you to put more than one commands in the same text file and then it will executes them automatically.

Using WP-CLI can give you many more advantages besides the above, and we will describe them in detail in the following parts.

How to Install WP-CLI

There is more than one way to have WP-CLI installed. And this part will briefly introduce three most widely used methods for you to choose from.

System Requirements

Before installing WP-CLI, you should ensure that you already have a hosting account with SSH access. Many reputable hosting providers offer you access to SSH once sign-up, such as Bluehost. You can read our Best SSH Hosting to know more information, if you wish.

Other basic requirements include:

  • PHP 5.3.2 version or later;
  • WordPress 3.4 version or later;
  • UNIX-like environment such as Linux.

If you have purchased a hosting solution powered by Grid technology, you can feel free to get started with WP-CLI because the WP-CLI have been installed and configured in advance under this environment.

Installing WP-CLI via Phar

If you have connected to your server’s command line interface through SSH, the first thing you should do is to download a Phar build. To have the latest version of wp-cli.phar, you can make use of curl or wget, and type a command like:


Then, run a simple command to make clear whether it works well:


When assuring the file works as expected, you now need to make it executable and place it on your PATH. This is a crucial step to make sure that you can type wp correctly rather than php.wp-cli.phar. Feel ease to type commands like below:


The last step is to run wp—info for figuring out whether you have installed WP-CLI successfully or not. If for sure, you will see output represented like:


Congratulations, you’re now an official user of WP-CLI!

Installing nightly via Phar

As the bleeding-edge WP-CLI version, nightly is welcomed by many WordPress developers. Built straight from the master branch, the installation of nightly is the same as we mentioned before, but without changing the URL to the phar file.

Installing WP-CLI on Windows

If you happen to attach to an environment of Windows, the way of installing WP-CLI will be a little different from others. As usual, you should first ensure that you already installed php before and moved it to your PATH. The next step is also to have wp-cli.phar downloaded and save it to a random folder like c:\wp-cli.

Then, create and name a file wp.bat under c:\wp-cli with the following contents:


What you need to do now is to add the folder c:\wp-cli to you PATH by typing following command:


Now, you can freely use WP-CLI in command line of Windows from anywhere as you like.

How to Use WP-CLI

The ultimate goal of WP-CLI is to help webmasters find a much easier way for managing their WordPress sites, that is, whatever you want to use the WordPress admin can find an alternative way with WP-CLI and in a more convenient solution.

Update WordPress using WP-CLI

In the help of WP-CLI, you can easily update your WordPress to the latest version, typing a simple command:


Along with your WordPress updating, you will always need to have the database updated as well. For that, you need a command like this:


Then you can type another command to check if your site is running with the latest version of WordPress:


Configure WordPress Plugin with WP-CLI

Unlike using the WordPress admin interface that search for a plugin you are working with for more than one steps, WP-CLI makes it possible for you to list all plugins with just a command:


You can also use WP-CLI search option to instantly know all plugins relating to a certain term. Just in the case of SEO related plugins, you can have the answer by tying command like this:


Likewise, using WP-CLI to have a new plugin installed or activated is much faster than using a web browser. Whatever plugin you want to install, you just need to replace the name in the below command with the plugin’s name:


Other more, if you need to update all plugins your site is running, you can use a command like this:


Backup and restore a WordPress database

Keeping backing up the database of your WordPress periodically can prevent data losing in a sudden event. WP-CLI has a backup functionality, but if you want to back up your database automatically, you still need to make use of a cron job. First, type a command as it shows in the following:


After that, you need a .sql file and store it in a safe place. To import the database into WordPress as required, you can use a command as follows and don’t forget to replace the filename with your database backup file’s name:


Backup and restore WordPress content

When backing up and restoring your WordPress database, you will always want to do the same thing with your site content at the same time. WP-CLI enables you to easily export your pages, posts, categories, comments and other site content to a WXR file. The first step is to type a command like this:


Similar to database backup and restore, you should ensure to have an .xml file out there in a safe folder. Whenever you need importing a WXR file into WordPress, you can have it by following the command and change the filename to your backup file’name:



After analyzing WP-CLI from its advantages, installation and usability, we can see that it is definitely a powerful tool for webmasters. No matter when you want to manage your WordPress site and no matter what you need it for, WP-CLI helps you successfully and easily achieve that. Without any doubt, using WP-CLI is a good way to speed up your tasks and save your time so that you have more time to focus on boosting your own business.

Fortunately, through our reviewing, we found that many hosting providers have offered WP-CLI by default on their WordPress installations, including Bluehost, LiquidWeb, MediaTemple and many more. I also believe you can find the best web hosting solution offering WP-CLI for your WordPress site as per your specific needs.

Leave a Reply