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 docker compose up --wait
First, create a PHP debug remote server configuration:
Settings/Preferences
dialog, go to PHP | Servers
api
(or whatever you want to use for the variable PHP_IDE_CONFIG
)localhost
(or the one defined using the SERVER_NAME
environment variable)443
Xdebug
Use path mappings
api/
directory to the /app
absolute path on the serverYou can now use the debugger!
In PhpStorm, open the Run
menu and click on Start 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
, where api
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 VSCode, 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 ofhost.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
…
Made with love by
Les-Tilleuls.coop can help you design and develop your APIs and web projects, and train your teams in API Platform, Symfony, Next.js, Kubernetes and a wide range of other technologies.
Learn more