This section provides a handful selection of tutorials that will help you get started with PHP debugging in PhpStorm.
Fix Xdebug on PhpStorm when run from a Docker container. Long story short: There is a bug in the networking setup of Docker for Win that makes PhpStorm use the wrong remotehost when it starts a debugging session. When you take a look at the 'Console' panel at the bottom of the IDE, you should see something like this.
- Hello, I am learning php and use the PhpStorm IDE. In school we use XAMPP as server and xDebug as debug plugin. I have installed everything and i can 'run' code but can't debug, when i start a session, the breakpoints seem to be ignored.
- Older versions of PHPStorm will not work with newer versions of XDebug. A common error you'll run into is breakpoints only working on index.php and not being able to step over or into code. Finally, make sure the version of XDebug you're using is compatible with the version of PHP you're running. For instance, PHP 7.3 and 7.4 use XDebug 2.9.
Quick Start
Before proceeding with any of the debugging scenarios, you need to choose a debugging engine and install it in your PHP environment. These tutorials will guide you through the installation process:
Phpstorm Xdebug Vagrant
With the debugging engine installed, you can start debugging by following the zero-configuration debugging approach:
Choose and install the browser extension suitable for your browser.
On the PhpStorm toolbar, toggle to start listening for incoming PHP debug connections, or choose Run | Start Listening for PHP Debug Connections from the main menu.
Set a breakpoint in your code. Breakpoints can be set in the PHP context inside PHP, HTML, TWIG, BLADE, and files of other types. Line breakpoints can be set only on executable lines, but not on comments, declarations, or empty lines. For details on getting started with Twig and Blade debugging, refer to Debug Twig templates and Debug Blade templates.
Start the debugging session in the browser using the installed browser extension.
During a debugging session, examine the program state: see variable values, evaluate expressions, step through the program, and so on.
See Zero-configuration debugging for the detailed step-by-step instructions, and Advanced debugging scenarios for more debugging scenarios.
Debugging a PHP web application
Depending on your environment, you can debug your PHP Web application locally or remotely.
Local debugging | Remote debugging |
---|---|
The debugging engine and PhpStorm are running on the same machine. | The debugging engine is running on a remote environment (for example, a remote server or a virtual machine). |
Follow the Zero-configuration debugging procedure. |
|
Phpstorm Xdebug Xampp Download
To test direct connection, run the telnet host 9000
(for Xdebug) or the telnet host 10137
(for Zend Debugger) command on the remote server and ensure that connection is established. Here, host
is the IP address of the local machine PhpStorm is running on.
To check for opened inbound ports, you can use canyouseeme.org or a similar service.
Debugging a PHP CLI script
Depending on your environment, you can debug your PHP CLI script locally or remotely.
Local debugging | Remote debugging |
---|---|
The debugging engine and PhpStorm are running on the same machine. | The debugging engine is running on a remote environment (for example, a remote server or a virtual machine). |
Follow the Debug a PHP CLI script procedure. |
|
Besides running an entire application, you may want to run a PHPUnit or Behat test that covers a specific class, function or scenario, with the debugging engine attached. To learn how to do it, follow the Create a test configuration for a specific target procedure.
Troubleshooting
When using Xdebug or Zend Debugger with PhpStorm, some misconfiguration can prevent the debugger from working. In the Troubleshooting guide, you will find the description of some common issues and learn how to troubleshoot them.
Advanced debugging scenarios
The following topics will assist you in exploring the advanced debugging scenarios in PhpStorm:
03 Dec 2020
Requirements
- XAMPP for Windows: https://www.apachefriends.org/download.html
Setup
- Download Xdebug for the specific PHP version:
- PHP 8.0 (64-Bit): https://xdebug.org/files/php_xdebug-3.0.0-8.0-vs16-x86_64.dll
- Move the downloaded dll file to:
C:xamppphpext
- Rename the dll file to:
php_xdebug.dll
- Open the file
C:xamppphpphp.ini
with Notepad++ - Disable output buffering:
output_buffering = Off
- Scroll down to the
[XDebug]
section (or create it) and copy/paste these lines:
- Restart Apache
PhpStorm
- Enable the Xdebug option: “Can accept external connections” and “Additionally listen on Xdebug 3 default port 9003”. Screenshot
- Use the PhpStorm bookmarklets generator to activate Xdebug from the browser side.
Netbeans
- Change the Netbeans debugging options: Screenshot
Visual Studio Code
- Install the PHP Debug Adapter for Visual Studio Code.
Postman
Add XDEBUG_SESSION_START=PHPSTORM
as query parameter to the url, e.g.
- http://localhost?XDEBUG_SESSION_START=PHPSTORM
Start debugger from the console
Enter cmd: