PhpStorm 2018.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 PHP Command Line Tools.

For information about running the tool in the command line mode, see PHP Command Line Tools.

Before you start

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 as described in Composer Dependency Manager.

Click Create. The create-project Composer command will be invoked with the selected package. As a result, the Composer project will be created, whose configuration and structure depends on the selected package. After that, the created PhpStorm project opens.

  1. On the context menu of composer.json, choose Composer | Manage Dependencies.

  2. In the Manage Composer Dependencies Dialog that opens, select the wp-cli/wp-cli package from the Available Packages list, possibly using the search field.

    Choose the relevant version from the Version to install list.

  3. If necessary, expand the Settings hidden area and specify the advanced installation options.

    In the Command line parameters field, type the additional command line parameters. It is recommended to provide the --dev, option: the the package in this case is added to the require-dev section of the composer.json file instead of the default require section.

  4. Click Install.

Configuring wp-cli as a PhpStorm command line tool

  1. Download the wp-cli.phar at WordPress CLI.

  2. Open the Settings / Preferences Dialog by pressing Ctrl+Alt+S or by choosing File | Settings for Windows and Linux or PhpStorm | Preferences for macOS, and click Command Line Tool Support under Tools.

  3. On the Command Line Tool Support page, click the Add button. In the Choose Tool to Add dialog box that opens, choose WP-CLI.

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

      Choose one of the configured PHP interpreters from the PHP Interpreter list. See Configuring Remote PHP Interpreters for details.

      In the Path to phar text box, specify the location of the wp-cli.phar archive. Type the path manually or click Browse 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 Browse browseButton.png and choose the desired location in the dialog box that opens.

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

  6. From the Console encoding drop-down list, choose the character set to show the tool's output in theCommand Line Tools Console Tool Window.

  7. In the Show console in area, choose Pop-up to open the Input pane in a pop-up window orTool window to show it as a field at the bottom of the Command Line Tools Console tool window.

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 PHP Command Line Tools.

Last modified: 14 December 2018

See Also