Using Xdebug #
The default development image is shipped with Xdebug, a popular debugger and profiler for PHP.
When using Dev Containers, Xdebug is pre-configured and works out of the box. Open the Run and Debug panel in Visual Studio Code and start the Debug PHP launch configuration, then set your breakpoints and load a page.
For other setups, because it has a significant performance overhead, the step-by-step debugger
is disabled by default.
It can be enabled by including debug in the values of the XDEBUG_MODE environment variable.
On Linux and Mac:
XDEBUG_MODE=develop,debug docker compose up --wait
On Windows:
set XDEBUG_MODE=develop,debug&& docker compose up --wait&set XDEBUG_MODE=
Debugging with Xdebug and PhpStorm #
First, create a PHP debug remote server configuration:
- In the
Settings/Preferencesdialog, go toPHP | Servers - Create a new server:
- Name:
symfony(or whatever you want to use for the variablePHP_IDE_CONFIG) - Host:
localhost(or the one defined using theSERVER_NAMEenvironment variable) - Port:
443 - Debugger:
Xdebug - Check
Use path mappings - Absolute path on the server:
/app
- Name:
You can now use the debugger!
-
In PhpStorm, open the
Runmenu and click onStart Listening for PHP Debug Connections -
Add the
XDEBUG_SESSION=PHPSTORMquery parameter to the URL of the page you want to debug, or use other available triggersAlternatively, you can use the Xdebug extension for your preferred web browser.
-
On the command line, we might need to tell PhpStorm which path mapping configuration should be used, set the value of the PHP_IDE_CONFIG environment variable to
serverName=symfony, wheresymfonyis the name of the debug server configured above.Example:
XDEBUG_SESSION=1 PHP_IDE_CONFIG="serverName=symfony" php bin/console ...
Debugging with Xdebug and Visual Studio Code #
-
Install necessary PHP extension for Visual Studio Code.
-
Add debug configuration into your
.vscode\launch.jsonfile.Example:
{ "version": "0.2.0", "configurations": [ { "name": "Debug PHP", "type": "php", "request": "launch", "pathMappings": { "/app": "${workspaceFolder}" } } ] } -
Use Run and Debug options and run
Debug PHPto listen for upcoming connections with the Xdebug extension installed and active.
Troubleshooting #
Inspect the installation with the following command. The Xdebug version should be displayed.
$ docker compose exec php php --version
PHP ...
with Xdebug v3.x.x ...