PhpStorm 2016.2 Help

Configuring Xdebug

On this page:

Downloading and installing the Xdebug debugging engine

Download the Xdebug extension compatible with your version of PHP and save it in the php/ folder.

  • The location of the php/ folder is defined during the installation of the PHP engine.
  • If you are using an AMP package, the Xdebug extension may be already installed. Follow the instructions in the xdebug.txt.

Enabling Xdebug integration with the PHP engine

  1. Open the active php.ini file in the editor:
    1. Open the Settings / Preferences Dialog by choosing File | Settings for Windows and Linux or PhpStorm | Preferences for OS X, and click PHP under Languages&Frameworks.
    2. On the PHP page that opens, click browseButton.png next to the Interpreter field.
    3. In the Interpreters dialog box that opens, the Configuration File read-only field shows the path to the active php.ini file. Click Open in Editor.
  2. To disable the Zend Debugger and Zend Optimizer tools, that blocks Xdebug, remove or comment the following lines in the php.ini file:
    zend_extension=<path_to_zend_debugger> zend_extension=<path_to_zend_optimizer>
  3. To enable Xdebug, locate the [Xdebug] section in the php.ini file and update it as follows:
    [Xdebug] zend_extension="<path to php_xdebug.dll>" xdebug.remote_enable=1 xdebug.remote_port="<the port for Xdebug to listen to>" (the default port is 9000) xdebug.profiler_enable=1 xdebug.profiler_output_dir="<AMP home\tmp>"
  4. To enable multiuser debugging via Xdebug proxies, locate the xdebug.idekey setting and assign it a value of your choice. This value will be used to register your IDE on Xdebug proxy servers.
  5. Save and close the php.ini file.

Integrating Xdebug with PhpStorm

  1. Open the Settings / Preferences Dialog by choosing File | Settings for Windows and Linux or PhpStorm | Preferences for OS X, and click PHP under Languages&Frameworks.
  2. Check the Xdebug installation associated with the selected PHP interpreter:
    1. On the PHP page, choose the relevant PHP installation from the Interpreter drop-down list and click the Browse button browseButton next to the field. The list shows all the PHP installations available in PhpStorm, see Enabling PHP Support.
    2. The Interpreters dialog box that opens shows the following:
      • The version of the selected PHP installation.
      • The name and version of the debugging engine associated with the selected PHP installation (Xdebug or Zend Debugger). If no debugger is configured, PhpStorm shows Debugger: Not installed.

    Alternatively, open the Xdebug checker, paste the output of the phpinfo(), and click Analyze my phpinfo() output.

    Learn more about checking the Xdebug installation in Validating the Configuration of a Debugging Engine.

  3. Define the Xdebug behaviour. Click Debug under the PHP node. On the Debug page that opens, specify the following settings in the Xdebug area:
    • In the Debug Port text box, appoint the port through which the tool will communicate with PhpStorm. This must be exactly the same port number as specified in the php.ini file:
      xdebug.remote_port = <port_number>

      By default, Xdebug listens on port 9000.

    • To have PhpStorm accept any incoming connections from Xdebug engines through the port specified in the Debug port text box, select the Can accept external connections check box.
    • Select the Force break at the first line when no path mapping is specified check box to have the debugger stop as soon as it reaches and opens a file that is not mapped to any file in the project on the Servers page. The debugger stops at the first line of this file and Debug Tool Window. Variables shows the following error message: Cannot find a local copy of the file on server <path to the file on the server> and a link Click to set up mappings. Click the link to open the Resolve Path Mappings Problem dialog box and map the problem file to its local copy.

      When this check box cleared, the debugger does not stop upon reaching and opening an unmapped file, the file is just processed, and no error messages are displayed.

    • Select the Force break at the first line when the script is outside the project check box to have the debugger stop at the first line as soon as it reaches and opens a file outside the current project. With this check box cleared, the debugger continues upon opening a file outside the current project.
  4. In the External Connections area, specify how you want PhpStorm to treat connections received from hosts and through ports that are not registered as server configurations.
    • Ignore external connections through unregistered server configurations: Select this check box to have PhpStorm ignore connections received from hosts and through ports that are not registered as server configurations. When this check box is selected, PhpStorm does not attempt to create a server configuration automatically.
    • Detect path mappings from deployment configurations:
      • When this check box is selected, PhpStorm attempts to retrieve path mappings for debugging in a remote environment from the server access configuration (deployment configuration).
      • When the check box is cleared, you have to specify the path mappings manually.
      See Validating the Configuration of a Debugging Engine, Web Server Debug Validation Dialog, and Configuring Remote PHP Interpreters for details.
    • Break at first line in PHP scripts: Select this check box to have the debugger stop as soon as connection between it and PhpStorm is established (instead of running automatically until the first breakpoint is reached). Alternatively turn on the Run | Break at first line in PHP scripts option on the main menu.
    • Max. simultaneous connections: Use this spin box to limit the number of external connections that can be processed simultaneously.

Configuring Xdebug for Using in the On-Demand Mode

Starting with version 2016.2, PhpStorm supports the On-Demand mode where you can disable Xdebug for your global PHP installation, and have it enabled automatically on demand only when you are debugging your command-line scripts or when you need code coverage reports. This lets your command line scripts (including Composer and unit tests) run much faster.

  1. Disable Xdebug for command-line scripts:
    1. Open the Settings / Preferences Dialog by choosing File | Settings for Windows and Linux or PhpStorm | Preferences for OS X, and click PHP under Languages&Frameworks.
    2. From the PHP executable drop-down list, choose the relevant PHP interpreter and click browseButton next to it. In the Interpreters dialog box that opens, click the Open in Editor link next to the Configuration file: <path to php.ini> file. Close all the dialog boxes and switch to the tab where the php.ini file is opened.
    3. In the php.ini file, find the [XDebug] section and comment the following line in it by adding ; in preposition:
      ;[XDebug] ;zend_extension = "<full_path_to_xdebug>"
    4. Open the Interpreters dialog box and click refresh next to the PHP executable field. PhpStorm informs you that debugger is not installed:
      ps_interpreters_debugger_not_installed.png
  2. To enable PhpStorm to activate Xdebug when it is necessary, specify the path to it in the Debugger extension text box, in the Additional area. Type the path manually or click browseButton and select the location in the dialog box that opens.

Configuring Xdebug for Using in the Just-In-Time Mode

PhpStorm supports the use of Xdebug in the Just-In-Time (JIT) mode so it is not attached to your code all the time but connects to PhpStorm only when an error occurs or an exception is thrown. The Xdebug operation mode is toggled through the xdebug.remote_mode setting, which is by default set to req. The mode is available both for debugging command-line scripts and for web server debugging.

  1. Find the currently loaded php.ini file and open it in the editor. This can be done in two ways:
    • For command-line scripts:
      1. Open the Settings / Preferences Dialog by choosing File | Settings for Windows and Linux or PhpStorm | Preferences for OS X, and click PHP under Languages&Frameworks.
      2. From the PHP executable drop-down list, choose the relevant PHP interpreter and click browseButton next to it. In the Interpreters dialog box that opens, click the Open in Editor link next to the Configuration file: <path to php.ini> file. Close all the dialog boxes and switch to the tab where the php.ini file is opened.
    • For Web servers:
      1. On the main menu, choose Run | Web Server Debug Validation.
      2. In the Web Server Debug Validation Dialog that opens, choose the Web server to validate the debugger on.
        • Choose Local Web Server or Shared Folder to check a debugger associated with a local Web server.
          • Path to Create Validation Script: In this field, specify the absolute path to the folder under the server document root where the validation script will be created. For Web servers of the type Inplace, the folder is under the project root.

            The folder must be accessible through http.

          • URL to Validation Script: In this text box, type the URL address of the folder where the validation script will be created. If the project root is mapped to a folder accessible through http, you can specify the project root or any other folder under it.
        • Choose Remote Web Server to check a debugger associated with a remote server.
          • Path to Create Validation Script: In this field, specify the absolute path to the folder under the server document root where the validation script will be created. The folder must be accessible through http.
          • Deployment Server: In this field, specify the server access configuration of the type Local Server or Remote Server to access the target environment. For details see Configuring Synchronization with a Web Server.

            Choose a configuration from the drop-down list or click the Browse button browseButton in the Deployment dialog.

      3. Click Validate to have PhpStorm create a validation script, deploy it to the target remote environment, and run it there.
      4. Open the php.ini file which is reported as loaded and associated with Xdebug.
  2. In the php.ini file, find the [XDebug] section and change the value of the xdebug.remote_mode from the default req to jit.

See also Just-In-Time debugging and PHP Exception Breakpoints with PhpStorm and Xdebug

See Also

Last modified: 20 July 2016