XDebug is a debugging and profiling extension for PHP. This guide covers how to use XDebug in your development environment.
The quickest way to run PHP with XDebug enabled is using the xdebug-console command:
dev xdebug-consoleThis starts a PHP console with XDebug pre-configured and ready to connect to your IDE.
- Go to Settings > PHP > Debug
- Set XDebug port to
9003(XDebug 3.x) or9000(XDebug 2.x) - Enable "Can accept external connections"
- Go to Settings > PHP > Servers
- Add a server:
- Name:
docker - Host: Your project hostname (e.g.,
project.localhost) - Port:
80 - Debugger:
Xdebug - Enable "Use path mappings"
- Map your local project directory to
/data/workspace/customer/project
- Name:
Install the "PHP Debug" extension and add to .vscode/launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"port": 9003,
"pathMappings": {
"/data/workspace/customer/project": "${workspaceFolder}"
}
}
]
}Execute any PHP script with XDebug:
dev xdebug-console php myscript.phpFor Magento:
dev xdebug-console bin/magento cache:flushFor Composer:
dev xdebug-console composer installXDebug is available in the PHP containers but not enabled by default for performance reasons. To debug web requests:
-
Set the XDebug trigger in your browser:
- Install a browser extension (XDebug helper for Chrome/Firefox)
- Or add
?XDEBUG_SESSION_START=PHPSTORMto your URL
-
Start listening for connections in your IDE
-
Access your application in the browser
-
Your IDE should break on the first line or your breakpoints
XDebug can also profile your application to identify performance bottlenecks:
dev xdebug-console php -d xdebug.mode=profile myscript.phpProfile files are generated in /tmp inside the container.
Verify XDebug is loaded:
dev xdebug-console php -vYou should see "with Xdebug" in the output.
Ensure port 9003 isn't blocked by your firewall and your IDE is listening on the correct port.
Make sure your IDE's path mappings match your workspace structure. The container path is always /data/workspace/...