WP-CLI command line tool
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
Make sure the PHP interpreter is configured in PhpStorm on the PHP page, as described in Configure local PHP interpreters and Configure remote PHP interpreters.
Make sure the PHP and Command Line Tool Support plugins are installed and enabled.
The plugins are activated by default. If the plugins are disabled, enable them on the Installed tab of the Plugins page as described in Install plugins.
Configure the PHP interpreter to use WordPress with, as described Configure remote PHP interpreters. Note that WordPress requires PHP 5.3 or later.
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.
Inside composer.json, add the
wp-cli/wp-clidependency record to the
require-devsection. Press Ctrl+Space to get code completion for the package name and version.
Do one of the following:
Click the Install shortcut link on top of the editor panel.
If the Non-installed Composer packages inspection is enabled, PhpStorm will highlight the declared dependencies that are not currently installed. Press Alt+Enter and select whether you want to install a specific dependency or all dependencies at once.
Using WP-CLI as a PhpStorm command line tool
Before you begin, download the wp-cli.phar at WordPress CLI.
Configure WP-CLI as a command line tool
In the Settings dialog (Ctrl+Alt+S), go to .
Click on the toolbar.
In the Command Line Tools dialog, choose WP-CLI from the list, and specify its visibility level (Project or Global).
When you click OK, the WP-CLI dialog opens.
Choose the way to run WP-CLI:
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 Configure local PHP interpreters and Configure remote PHP interpreters for details.
In the Path to phar field, specify the location of the wp-cli.phar archive. Type the path manually or click and choose the desired location in the dialog that opens.
Executable available (installed via Composer, and so on): 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 and choose the desired location in the dialog that opens.
Click OK to apply changes and return to the Command Line Tool Support page. Optionally, click to edit the tool properties, or to customize the commands set. See Customize a tool for details.
Run WP-CLI commands
You can run WP-CLI commands and analyze their output right in PhpStorm, just as the commands of any other command line tools, see PHP command line tools.
From the main menu, chooseor press Ctrl twice.
In the Run Anything window that opens, type the call of the command in the
The command execution result is displayed in the Run tool window.
Terminate a command
Click on the Run tool window toolbar.
Debug WP-CLI commands
Wordpress commands are defined in controller classes that extend
WP_CLI_Command, as well as in arbitrary functions. To debug a command, it is crucial that you initiate a debugging session for the command itself, and not the controller class or the file it is defined in. Otherwise, the Wordpress bootstrapping process will be skipped, and the execution will fail.
In the controller class or the file corresponding to the selected command, click the editor gutter at a code line where you want to set a breakpoint.
Create a run/debug configuration that will run the wp-cli tool with the selected command. In the main menu, select , then click and choose PHP Script from the list.
In the PHP Script dialog, provide the run/debug configuration parameters.
In the File field, provide the path to the wp-cli executable file.
In the Arguments field, type the actual command and its arguments, such as
On the PhpStorm toolbar, select the created run/debug configuration and click . The command execution will stop at the specified breakpoint.