PhpStorm 2016.3 Help

Using the WordPress Command Line Tool WP-CLI

To run WordPress in the command line mode, you will need a set of command line tools which you can acquire by installing the wp-cli/wp-cli package using the Composer dependency manager or by downloading the wp-cli.phar archive. The downloaded command line tool must be registered in PhpStorm as described in Using Command Line Tools.

For information about running the tool in the command line mode, see Running Command Line Tool Commands.

On this page:

Before you start

  1. Make sure the PHP interpreter is configured in PhpStorm on the PHP page, as described in Enabling PHP support.
  2. Make sure the PHP and Command Line Tool Support plugins are installed and enabled. The plugins are bundled with PhpStorm and activated by default. If the plugins are not activated, enable them on the Plugins page of the Settings / Preferences Dialog as described in Enabling and Disabling Plugins.
  3. Configure the PHP interpreter to use WordPress with, as described Configuring Remote PHP Interpreters. Note that WordPress requires PHP 5.3 or higher.

Installing the wp-cli package using the Composer dependency manager

Before you start, make sure Composer is installed on your machine and initialized in the current project, see Using Composer Dependency Manager.

  1. On the main menu, choose Tools | Composer | Add Dependency.
  2. In the Add Composer Dependency dialog that opens, select the wp-cli/wp-cli package from the Available Packages list, possibly using the search field. The list shows all the available packages, however, the packages that have been already installed are marked with a tick.

    Choose the relevant version from the Version to install drop-down list.

  3. If necessary, expand the Settings hidden area and specify the advanced installation options. In the Command line parameters text box, type the additional command line parameters to adjust the add dependency procedure. For example, to have the package added to the require-dev section instead of the default require section type -dev. For more information about Composer command line options during installation, see https://getcomposer.org/doc/03-cli.md.
  4. Click Install.

When you click Create, the create-project command is invoked with the selected package. This results in creating a Composer project whose configuration and structure depends on the selected package, see https://getcomposer.org/doc/03-cli.md#create-project for details. After that a PhpStorm project opens.

Downloading the wp-cli.phar archive

Configuring wp-cli as a PhpStorm command line tool

  1. Open the Settings / Preferences Dialog by pressing Ctrl+Alt+S or by choosing File | Settings for Windows and Linux or PhpStorm | Preferences for OS X, and click Command Line Tool Support under Tools.
  2. On the Command Line Tool Support page, click the Add button. In the Choose Tool to Add dialog box that opens, choose WP-CLI.
  3. In the WP-CLI dialog box that opens, choose the way to run WordPress:
    • Installed via PHAR: Choose this option to launch WordPress through a PHP script or have PhpStorm detect and start the launcher in the wp-cli.phar archive.

      In the Path to PHP executable field, specify the location of the PHP engine installation folder. Choose the PHP installation from the list, or type the path manually, or click the Browse button browseButton.png and choose the desired location in the dialog box that opens.

      In the Path to phar text box, specify the location of the wp-cli.phar archive. Type the path manually or click the Browse button browseButton.png and choose the desired location in the dialog box that opens.

    • Executable available (installed via Composer, etc.): choose this option to launch WordPress through an executable file which is available when you install WordPress using a package management tool, for example, Composer.

      In the Path to wp.bat field, specify the location of the wp.bat or wp executable file. If you used Composer, the default location is \vendor\wp\cli\bin\wp or \vendor\wp\cli\bin\wp.bat. Type the path manually or click the Browse button browseButton.png and choose the desired location in the dialog box that opens.

  4. When you click OK, the WP-CLI dialog box closes and PhpStorm brings you back to the Command Line Tool Support page, where wp is added to the list of available tools.
  5. From the Console encoding drop-down list, choose the character set to show the tool's output in the Command Line Tools Console Tool Window.
  6. In the Show console in area, specify where you want the Input pane for typing commands opened:
    • To have the Input pane opened in a pop-up window, choose the Pop-up option.
    • To have the Input pane opened as a text box at the bottom of the Command Line Tools Console tool window, choose the Tool window option.

Running the wp-cli tool

You can run WP-CLI commands and analyze their output right in PhpStorm using the dedicated Command Line Tools Console tool window, just as the commands of any other command line tools, see Running Command Line Tool Commands.

See Also

Last modified: 23 March 2017