VS Code listens for Xdebug and can map paths from a container or remote PHP-FPM instance to local project files.
What It Does
Connect a container to a reachable debugger host. Map server source paths to the VS Code workspace.
Requirements and Compatibility
Use a supported PHP runtime and install any third-party tool or extension explicitly shown in the examples. Commands should be run from the project root unless stated otherwise.
Syntax, Inputs and Results
The examples separate configuration, the smallest working operation and a realistic follow-up task. Adapt file paths and dependency versions to your own project.
Example 1: Basic Use
Connect a container to a reachable debugger host.
zend_extension=xdebug
xdebug.mode=debug
xdebug.start_with_request=trigger
xdebug.client_host=host.docker.internal
xdebug.client_port=9003
xdebug.discover_client_host=0
Example 2: Another Case
Map server source paths to the VS Code workspace.
{"version":"0.2.0","configurations":[{"name":"Listen from container","type":"php","request":"launch","port":9003,"pathMappings":{"/var/www/html":"${workspaceFolder}"}}]}
Practical Example
Check settings before triggering the debug session.
php -i | grep -E 'xdebug.mode|xdebug.client_host|xdebug.client_port'
XDEBUG_TRIGGER=1 php bin/debug-demo.php
For production, apply the compatibility and edge-case limits described below.
Important Behavior and Edge Cases
Path mappings must match the remote filesystem; correct ports alone cannot resolve source breakpoints.
Comparison with Related Functions and Tools
| Subject | Key difference |
|---|---|
| Step debugging vs profiling | Step debugging pauses individual statements; profiling records aggregate runtime cost. |
Common Beginner Mistakes
| Mistake | Correct approach |
|---|---|
| Enabling the debugger for every production request | Use controlled triggers and disable development modes in production. |
| Skipping the prerequisite of this specific workflow | Install or configure the named tool and confirm the example can actually run. |
| Ignoring edge conditions | Path mappings must match the remote filesystem; correct ports alone cannot resolve source breakpoints. |
Key Takeaways
- VS Code listens for Xdebug and can map paths from a container or remote PHP-FPM instance to local project files.
- Path mappings must match the remote filesystem; correct ports alone cannot resolve source breakpoints.
- Keep application configuration, source code and validation tests under version control.
Use these examples as a starting point, then validate the result with the actual PHP build, dependencies and inputs used by your application.