If you run a WordPress website you can use WP-CLI or WordPress Command Line Interface to manage your site. This can make quick work out of updating plugins, setting up multisites, and much more without a web-browser.

If you have a lot of WordPress sites to manage, or would just like to become more efficient in your common WordPress tasks, learning to use WP-CLI is a great time investment.

A common scenario a WordPress administrator might run into, is updating all of the plugins across all of their various WordPress installations. With WP-CLI it's as easy as typing: wp plugin update --all

Install WordPress WP-CLI

To use WP-CLI you just need SSH access, PHP 5.3.2 or later, and at least WordPress 3.5.2.

  1. First you need to download wp-cli.phar using either wget or curl after you login with SSH.

    curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar

    wget https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar

    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

  2. Then test WP-CLI directly with PHP with this command:

    php wp-cli.phar --info

    You should see output similar to:

    PHP binary: /usr/local/bin/php
    PHP version: 5.4.28
    php.ini used: /usr/local/lib/php.ini
    WP-CLI root dir: phar://wp-cli.phar
    WP-CLI global config:
    WP-CLI project config:
    WP-CLI version: 0.15.1

  3. Next you'll want 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

  4. Now you can simply use wp at the command line to access WP-CLI:

    wp --info

Setup bash tab completion 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.

  1. Download the WP-CLI tab completion file to your server.

    curl -O https://github.com/wp-cli/wp-cli/raw/master/utils/wp-completion.bash

    wget https://github.com/wp-cli/wp-cli/raw/master/utils/wp-completion.bash

    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://github.com/wp-cli/wp-cli/raw/master/utils/wp-completion.bash

  2. Move the WP-CLI tab completion file to your home directory:

    mv wp-completion.bash ~/

  3. Now edit your ~/.bash_profile file to include the WP-CLI tab completion file:

    vi ~/.bash_profile

  4. Add this line to the bottom of your ~/.bash_profile file:

    source ~/wp-completion.bash

    Now save this file

  5. Back at the command line, make sure to source your ~/.bash_profile file with this:

    source ~/.bash_profile

  6. Now just type wp at the prompt, and hit Tab twice to see all the tab completions you just setup:

    root@server [/home/example/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

Using the WordPress WP-CLI to manage a site

Now that you have WP-CLI installed on your server, you can begin using it to manage your WordPress installs.

  1. The first thing you need to do is navigate to the directory of a WordPress install:

    cd ~example/public_html/wordpress

  2. Now you can have WP-CLI spit back options for the type of activity you'd like to do. For instance if you'd like to manage the plugins of your WordPress install you can simply run:

    wp plugin

    You'll get a nice help listing of all the things you can do with plugins:

    usage: wp plugin activate <plugin>... [--network]
    or: wp plugin deactivate [<plugin>...] [--all] [--network]
    or: wp plugin delete <plugin>...
    or: wp plugin get <plugin> [--field=<field>] [--format=<format>]
    or: wp plugin install <plugin|zip|url>... [--version=<version>] [--force] [--activate] [--activate-network]
    or: wp plugin is-installed <plugin>
    or: wp plugin list [--<field>=<value>] [--field=<field>] [--fields=<fields>] [--format=<format>]
    or: wp plugin path [<plugin>] [--dir]
    or: wp plugin search <search> [--per-page=<per-page>] [--field=<field>] [--fields=<fields>] [--format=<format>]
    or: wp plugin status [<plugin>]
    or: wp plugin toggle <plugin>... [--network]
    or: wp plugin uninstall <plugin>... [--no-delete]
    or: wp plugin update [<plugin>...] [--all] [--version=<version>] [--dry-run]
    See 'wp help plugin <command>' for more information on a specific command.

  3. So let's just first list the currently installed plugins on our WordPress site:

    wp plugin list
    +------+--------+--------+---------+
    | name | status | update | version |
    +------+--------+--------+---------+
    +------+--------+--------+---------+
  4. We can see this WordPress install currently has no plugins installed, let's change that:

    wp plugin install hello-dolly
    Installing Hello Dolly (1.6)
    Downloading install package from https://downloads.wordpress.org/plugin/hello-dolly.1.6.zip...
    Using cached file '/root/.wp-cli/cache/plugin/hello-dolly-1.6.zip'...
    Unpacking the package...
    Installing the plugin...
    Plugin installed successfully.
    wp plugin install wp-super-cache
    Installing WP Super Cache (1.4)
    Downloading install package from https://downloads.wordpress.org/plugin/wp-super-cache.1.4.zip...
    Unpacking the package...
    Installing the plugin...
    Plugin installed successfully.
    wp plugin list
    +----------------+----------+--------+---------+
    | name           | status   | update | version |
    +----------------+----------+--------+---------+
    | hello-dolly    | inactive | none   | 1.6     |
    | wp-super-cache | inactive | none   | 1.4     |
    +----------------+----------+--------+---------+
  5. We can even take it a step further and go ahead and activate these plugins as well:

    wp plugin activate hello-dolly
    Success: Plugin 'hello-dolly' activated.
    wp plugin activate wp-super-cache
    Success: Plugin 'wp-super-cache' activated.
    wp plugin list
    +----------------+--------+--------+---------+
    | name           | status | update | version |
    +----------------+--------+--------+---------+
    | hello-dolly    | active | none   | 1.6     |
    | wp-super-cache | active | none   | 1.4     |
    +----------------+--------+--------+---------+

There is a lot more that you can do with WP-CLI and this was just a short intro to get you going. Be sure to check back often as we update our documentation on managing WordPress from the command line!

Did you find this article helpful?

We value your feedback!

Why was this article not helpful? (Check all that apply)
The article is too difficult or too technical to follow.
There is a step or detail missing from the instructions.
The information is incorrect or out-of-date.
It does not resolve the question/problem I have.
How did you find this article?
Please tell us how we can improve this article:
Email Address
Name

new! - Enter your name and email address above and we will post your feedback in the comments on this page!

Like this Article?

Comments

Post a comment
n/a Points
2014-06-25 2:53 pm
# wget https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
--2014-06-25 14:52:09-- https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
Resolving raw.githubusercontent.com... 23.235.40.133
Connecting to raw.githubusercontent.com|23.235.40.133|:443... connected.
ERROR: certificate common name `www.github.com' doesn't match requested host name `raw.githubusercontent.com'.
To connect to raw.githubusercontent.com insecurely, use `--no-check-certificate'.
Unable to establish SSL connection.
Staff
9,521 Points
2014-06-25 3:23 pm
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

Post a Comment

Name:
Email Address:
Phone Number:
Comment:
Submit

Please note: Your name and comment will be displayed, but we will not show your email address.

News / Announcements

WordPress wp-login.php brute force attack
Updated 2014-07-17 06:43 pm EST
Hits: 201023

Related Questions

Here are a few questions related to this article that our customers have asked:
Ooops! It looks like there are no questions about this page.
Would you like to ask a question about this page? If so, click the button below!
Ask a Question

Need more Help?

Search

Ask the Community!

Get help with your questions from our community of like-minded hosting users and InMotion Hosting Staff.

Current Customers

Chat: Click to Chat Now E-mail: support@InMotionHosting.com
Call: 888-321-HOST (4678) Ticket: Submit a Support Ticket

Not a Customer?

Get web hosting from a company that is here to help. Sign up today!