Watch the Debugging API Platform screencast
For development purposes such as debugging tests or remote API requests, Xdebug is shipped by default with the API Platform distribution.
To enable it, run:
XDEBUG_MODE=debug XDEBUG_SESSION=1 docker compose up --wait
First, create a PHP debug remote server configuration:
- In the
Settings/Preferences
dialog, go toPHP | Servers
- Create a new server:
- Name:
api
(or whatever you want to use for the variablePHP_IDE_CONFIG
) - Host:
localhost
(or the one defined using theSERVER_NAME
environment variable) - Port:
443
- Debugger:
Xdebug
- Check
Use path mappings
- Map the local
api/
directory to the/app
absolute path on the server
- Name:
You can now use the debugger!
-
In PhpStorm, open the
Run
menu and click onStart Listening for PHP Debug Connections
-
Add the
XDEBUG_SESSION=PHPSTORM
query parameter to the URL of the page you want to debug or use other available triggers. Alternatively, 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=api
, whereapi
is the name of the debug server configured higher.Example:
XDEBUG_SESSION=1 PHP_IDE_CONFIG="serverName=api" php bin/console ...
If you are using Visual Studio Code, use the following launch.json
to debug.
Note that this configuration includes the path mappings for the Docker image.
{
"version": "0.2.0",
"configurations": [
{
"name": "Listen for Xdebug",
"type": "php",
"request": "launch",
"port": 9003,
"log": true,
"pathMappings": {
"/app": "${workspaceFolder}/api"
}
}
]
}
Note
On Linux, the client_host
setting of host.docker.internal
may not work.
In this case you will need the actual local IP address of your computer.
Inspect the installation with the following command. The requested Xdebug version should be displayed in the output.
$ docker compose exec php \
php --version
PHP …
with Xdebug v…, Copyright (c) 2002-2021, by Derick Rethans
…