This guide explains how to configure Xdebug with PHP inside Docker for efficient debugging, including setting up the Xdebug configuration, rebuilding containers, resolving installation issues, configuring launch.json
, and verifying that debugging works correctly.
zend_extension=xdebug.so
xdebug.mode=develop,coverage,debug,profile
xdebug.idekey=docker
xdebug.start_with_request=yes
xdebug.log=/dev/stdout
xdebug.log_level=0
xdebug.client_port=9003
xdebug.client_host=host.docker.internal
xdebug.discover_client_host=true
RUN pecl install xdebug-3.3.2 && docker-php-ext-enable xdebug
COPY ext-xdebug.ini /usr/local/etc/php/conf.d/xdebug.ini
--network host
option to resolve the issue) Error ------
> [3/4] RUN pecl install xdebug-3.3.2 && docker-php-ext-enable xdebug:
6.897 No releases available for package "pecl.php.net/xdebug"
6.897 install failed
------
Dockerfile:3
--------------------
1 | FROM php:8.1-fpm
2 | WORKDIR /usr/share/nginx/html/docker-php
3 | >>> RUN pecl install xdebug-3.3.2 && docker-php-ext-enable xdebug
4 | COPY ext-xdebug.ini /usr/local/etc/php/conf.d/xdebug.ini
5 |
--------------------
ERROR: failed to solve: process "/bin/sh -c pecl install xdebug-3.3.2 && docker-php-ext-enable xdebug" did not complete successfully: exit code: 1
docker build --no-cache --network host -t [IMAGE] .
PHP Debug
extension in Visual Studio Code 5. Configure Xdebug in Visual Studio Code {
"name": "Listen for Xdebug",
"type": "php",
"request": "launch",
"port": 9003,
"log": false,
"externalConsole": false,
"pathMappings": {
"/usr/share/nginx/html/docker-php": "${workspaceFolder}",
},
}