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). Be sure to check out our guide to learn how to install WordPress, using WP-CLI.

Thoughts on “Install and Configure WP-CLI

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

  • # 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.

Leave a Reply