Install WP-CLI into a separated folder

WP-CLI (http://wp-cli.org/) is a great commandline tool to manage your WordPress installation. It has countless commands. For example to:

  • change database settings
  • clear the cache
  • manage comments and posts
  • install plugins

The “normal” installation is well documented on the project page. But I prefer to store my project tools (f.e.: vagrant, coposer, etc.) in a different tool folder that is separated from the WordPress installation.

To use wp-cli you have to take the following steps:

  1. Download the source into a folder where you wish to use the tool (f.e. ):
    $> wget https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar 
  2. Now you can call wp-cli like that
    $> php wp-cli.phar --path=/var/www/docroot/ help

    from within the install folder.

  3. Make wp globally available, so you can use it everywhere in your product structure:

    $> chmod +x wp-cli.phar # make it executable
    $> sudo cp wp-cli.phar /usr/local/bin/wp #copy it

    This step has to be repeated after every update!

  4. Now you can use wp as a “normal” command (but in my case I have to add the path param every time)
  5. As an alternative you can add a bash alias for the wp command with the path param (see command above):
    1. open .bash_aliases to edit it
      $> nano ~/.bash_aliases
    2. add the following line
      alias wp='php /var/www/tools/wp-cli/wp-cli.phar --path=/var/www/docroot/'

      Now you can call wp without the path param from any path within your project.

  6. Call $> wp help  to get information about usage

One thought on “Install WP-CLI into a separated folder

Leave a Reply

Your email address will not be published.

 

This site uses Akismet to reduce spam. Learn how your comment data is processed.