Install and Configure WP-CLI

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).

NOTE: InMotion Hosting’s WordPress Hosting includes WP-CLI and is already installed. If you are already familiar with working in a Command Line Interface (CLI), check out our WP-CLI Education Channel to learn about the commands available using WP-CLI.

Install WordPress WP-CLI

NOTE: The following instructions require root access available on a VPS or Dedicated Server.
  1. SSH into your server as the root user.
  2. 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

  3. 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
  4. 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

  5. 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.

  1. SSH into your server as the user that will be using WP-CLI.
  2. 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

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

    mv wp-completion.bash ~/

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

    vi ~/.bash_profile

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

    source ~/wp-completion.bash

    Now save this file

  6. Back at the command line, make sure to source your ~/.bash_profile file by running this command:

    source ~/.bash_profile

  7. 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!

JB
John-Paul Briones Content Writer II

John-Paul is an Electronics Engineer that spent most of his career in IT. He has been a Technical Writer for InMotion since 2013.

More Articles by John-Paul

7 thoughts on “Install and Configure WP-CLI

  1. 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

    1. 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.

  2. 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?

     

    1. 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.

  3. 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. 

  4. # 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.
    1. 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

Was this article helpful? Join the conversation!