Content · Web Development · PHP

Debugging PHP with Xdebug in VS Code

VS Code listens for Xdebug and can map paths from a container or remote PHP-FPM instance to local project files.

1 views Published Oct 17, 2026 Updated Oct 17, 2026 admin

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


SubjectKey difference
Step debugging vs profilingStep debugging pauses individual statements; profiling records aggregate runtime cost.

Common Beginner Mistakes


MistakeCorrect approach
Enabling the debugger for every production requestUse controlled triggers and disable development modes in production.
Skipping the prerequisite of this specific workflowInstall or configure the named tool and confirm the example can actually run.
Ignoring edge conditionsPath 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.

Share this resourceSend this page to someone who may find it useful.