- Download the Xdebug extension compatible with your version of PHP and save it in the
Integrating Xdebug with the PHP interpreter
Open the active php.ini file in the editor:
In the Settings/Preferences dialog (Ctrl+Alt+S), click PHP under Languages & Frameworks.
On the PHP page that opens, click next to the CLI Interpreter field.
In the CLI Interpreters dialog that opens, the Configuration File read-only field shows the path to the active php.ini file. Click Open in Editor.
To disable the Zend Debugger and Zend Optimizer tools, which block Xdebug, remove or comment out the following lines in the php.ini file:
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)
To enable multiuser debugging via Xdebug proxies, locate the
xdebug.idekeysetting and assign it a value of your choice. This value will be used to register your IDE on Xdebug proxy servers.
Save and close the php.ini file.
Verify Xdebug installation by doing any of the following:
In the command line, run the following command:
The output should list Xdebug among the installed extensions:
Create a php file containing the following code:
Open the file in the browser. The
phpinfooutput should contain the Xdebug section:
Configuring Xdebug in PhpStorm
In the Settings/Preferences dialog (Ctrl+Alt+S), select .
Check the Xdebug installation associated with the selected PHP interpreter:
On the PHP page, choose the relevant PHP installation from the CLI Interpreter list and click Browse next to the field. The list shows all the PHP installations available in PhpStorm, see Configuring Local PHP Interpreters and Configuring Remote PHP Interpreters.
- The CLI Interpreters dialog 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.
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:By default, Xdebug listens on port
xdebug.remote_port = <port_number>
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 checkbox.
- Select the Force break at the first line when no path mapping is specified checkbox 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 and map the problem file to its local copy.
When this checkbox 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 checkbox to have the debugger stop at the first line as soon as it reaches and opens a file outside the current project. With this checkbox cleared, the debugger continues upon opening a file outside the current project.
- In the External Connections area, specify how you want PhpStorm to treat connections received from hosts and through ports that are not registered as deployment server configurations.
Ignore external connections through unregistered server configurations: Select this checkbox to have PhpStorm ignore connections received from hosts and through ports that are not registered as deployment server configurations. When this checkbox is selected, PhpStorm does not attempt to create a deployment server configuration automatically.
Break at first line in PHP scripts: Select this checkbox 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 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
PhpStorm 2016.2 and later 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.
- Disable Xdebug for command-line scripts:
In the Settings/Preferences dialog (Ctrl+Alt+S), select PHP under Languages & Frameworks.
From the PHP executable list, choose the relevant PHP interpreter and click next to it. In the CLI Interpreters dialog that opens, click the Open in Editor link next to the Configuration file: <path to php.ini> file. Close all the dialogs and switch to the tab where the php.ini file is opened.
In the php.ini file, find the
[XDebug]section and comment the following line in it by adding
;[XDebug] ;zend_extension = "<full_path_to_xdebug>"
Open the CLI Interpreters dialog and click next to the PHP executable field. PhpStorm informs you that debugger is not installed:
To enable PhpStorm to activate Xdebug when it is necessary, specify the path to it in the Debugger extension field, in the Additional area. Type the path manually or click and select the location in the dialog 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.
Depending on whether you are going to debug command-line scripts or use a Web server, use one of the scenarios below.
For debugging command-line scripts, specify the custom
-dxdebug.remote_mode=jit directive as an additional configuration option:
In the Settings/Preferences dialog (Ctrl+Alt+S), navigate to .
From the PHP executable list, choose the relevant PHP interpreter and click next to it.
In the CLI Interpreters dialog box that opens, click next to the Configuration options text box in the Additional area.
- In the Configuration options dialog that opens, click to add a new entry, then type
-dxdebug.remote_modein the Configuration directive field and
jitin the Value field.
When you click OK, you return to the CLI Interpreters dialog box where the Configuration options text box shows
Web server debugging
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 field, 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, seeConfiguring Synchronization with a Web Server.
Choose a configuration from the list or click Browse in the Deployment dialog.
In the php.ini file, find the
[XDebug]section and change the value of the
xdebug.remote_modefrom the default
Configuring Xdebug running in a Docker container
To configure Xdebug running in a Docker container, provide the Xdebug-specific parameters in the Dockerfile, for example:
#Set up debugger RUN echo "xdebug.remote_enable=1" >> /etc/php/7.0/apache2/php.ini RUN echo "xdebug.remote_host=your_host_name_or_ip" >> /etc/php/7.0/apache2/php.ini
In this example, we're modifying /etc/php/7.0/apache2/php.ini providing the path to the Xdebug extension, and the
remote_host Xdebug parameters.
Note that the
xdebug.remote_host value should be replaced with the IP address of the machine where PhpStorm is running, which is accessible from the Docker container. If you are using Docker for Windows or Docker for Mac, you can set
host.docker.internal, which automatically resolves to the internal address of the host, letting you easily connect to it from the container.
Configuring Xdebug running on a Vagrant instance
[xdebug] zend_extension=/usr/lib/php5/20131226/xdebug.so xdebug.remote_enable=1 xdebug.remote_host=10.0.2.2 xdebug.remote_port=9000
Note that the
xdebug.remote_host value is
10.0.2.2. This is the gateway used in the default Vagrant setup, which allows to connect from the instance to host where PhpStorm is running.