PhpStorm Docker Compose interpreter and Xdebug path‑mapping ownership
0 reputation · 21 Oct 2025, 00:59 UTC
0 reputation · 21 Oct 2025, 00:59 UTC
When a project uses a docker-compose.yml service as the PHP CLI interpreter in PhpStorm, the IDE derives container paths from the compose volume mounts and working_dir. At the same time, Xdebug 3 expects matching path mappings in Settings > PHP > Servers and container‑side environment variables such as XDEBUG_MODE, XDEBUG_CLIENT_HOST, and XDEBUG_CLIENT_PORT. The repeatable‑environment goal is to keep a single source of truth for both the runtime and the debugger connection.
${VAR} or .env files) across PhpStorm releases and Docker Compose v2 versus the standalone binary?34775 reputation · 21 Oct 2025, 04:29 UTC
The docker-compose.yml service definition is the authoritative owner of the host-to-container path mapping. Volume mount targets and working_dir determine where files exist inside the container. PhpStorm's Docker Compose interpreter and Settings > PHP > Servers path mappings are mirrors of that runtime layout; Xdebug 3 environment variables control whether and where the debugger connects, not the path mapping.
working_dir define container paths..env or shell interpolation identically to docker compose config.Settings > PHP > Servers path mappings to map the container path reported during execution back to a local file.XDEBUG_MODE, XDEBUG_CLIENT_HOST, and XDEBUG_CLIENT_PORT do not encode host-to-container paths.Breakpoints miss or open the wrong file when the Compose file changes a mount target or working_dir and PhpStorm's Server mapping is not updated. Case sensitivity on Linux, trailing-slash differences, and different interpolation for host paths in Compose versus PhpStorm are common causes.
docker compose config from the project root and record the resolved volume target and working_dir for the PHP service..env and IDE mappings.Settings > PHP > Servers, add or edit the server, and set Path mappings so the local project path maps to the exact Compose container target from step 1. Match case and trailing slashes exactly.environment:
XDEBUG_MODE: develop,debug
XDEBUG_CLIENT_HOST: ${XDEBUG_CLIENT_HOST}
XDEBUG_CLIENT_PORT: 9003
docker compose config output with PhpStorm Settings > PHP > Servers path mappings and the Compose interpreter mapping. through the PhpStorm CLI interpreter. The echoed container path must appear as a Server mapping target.php -m | grep -i xdebug to confirm the extension is loaded, and run nc -zv $XDEBUG_CLIENT_HOST 9003 from inside the container to confirm the client host is reachable.Assumption: PhpStorm uses Docker Compose v2 (docker compose) on a Linux host. On Linux, prefer the Docker host-gateway address for XDEBUG_CLIENT_HOST; host.docker.internal is unreliable there. If you use standalone Compose v1 or Docker Desktop on Mac/Windows, replace docker compose with docker-compose and use the host address for that platform. If the reachability check fails, report host OS and Compose integration before changing mappings, because that changes the correct host address.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.