I solved this by adding the following lines into my Docker file:
# "xdebug-2.9.0" for PHP<=7.4 — "xdebug" (3) for PHP>=8
ARG XDEBUG_VERSION="xdebug-2.9.0"
FROM php:7.0-apache
RUN a2enmod rewrite
RUN docker-php-ext-install pdo pdo_mysql
RUN yes | pecl install ${XDEBUG_VERSION} \
&& echo "zend_extension=$(find /usr/local/lib/php/extensions/ -name xdebug.so)" > /usr/local/etc/php/conf.d/xdebug.ini \
&& echo "xdebug.remote_enable=on" >> /usr/local/etc/php/conf.d/xdebug.ini \
&& echo "xdebug.remote_autostart=off" >> /usr/local/etc/php/conf.d/xdebug.ini
COPY php.ini /usr/local/etc/php/
COPY . /var/www/html/
Answer from UrmLmn on Stack Overflow Top answer 1 of 7
52
I solved this by adding the following lines into my Docker file:
# "xdebug-2.9.0" for PHP<=7.4 — "xdebug" (3) for PHP>=8
ARG XDEBUG_VERSION="xdebug-2.9.0"
FROM php:7.0-apache
RUN a2enmod rewrite
RUN docker-php-ext-install pdo pdo_mysql
RUN yes | pecl install ${XDEBUG_VERSION} \
&& echo "zend_extension=$(find /usr/local/lib/php/extensions/ -name xdebug.so)" > /usr/local/etc/php/conf.d/xdebug.ini \
&& echo "xdebug.remote_enable=on" >> /usr/local/etc/php/conf.d/xdebug.ini \
&& echo "xdebug.remote_autostart=off" >> /usr/local/etc/php/conf.d/xdebug.ini
COPY php.ini /usr/local/etc/php/
COPY . /var/www/html/
2 of 7
40
try this:
RUN pecl install xdebug && docker-php-ext-enable xdebug
laravel - How to enable xdebug in php:7.4-fpm-alpine docker container? - Stack Overflow
My target is to use this git repo for Laravel with xdebug for php-fpm: https://github.com/aschmelyun/docker-compose-laravel When using this repo i run: docker-compose up -d --build site docker-com... More on stackoverflow.com
php - Configure Xdebug in Docker container - Stack Overflow
I'm trying to create a docker container with PHP and Xdebug to use step debugging. I use VSCode and somehow this debugger it's not working. Apparently the Dockerfile is not been executed when I use More on stackoverflow.com
phpstorm - Xdebug CLI in Docker - Stack Overflow
I read a lot of posts on GitHub and StackOverflow and I didn't find an answer. I have Docker container with PHP 7.4 and Xdebug 3. The IDE is PhpStorm. When I use Xdebug in browser, Xdebug works fin... More on stackoverflow.com
Where is Xdebug for PHP 8.4?
You can find an update from Derick from the start of the month here (5th November): https://derickrethans.nl/xdebug-update-october-2024.html In that he states: I made the first beta release of Xdebug 3.4 that is compatible with PHP 8.4, which is due to be released on November 21st. I hope to have a GA release of Xdebug 3.4.0 out around that date too. So he might just be a bit behind that original target, give him a little time. I also found a roadmap in the bugtacker targeting the 29th, but not sure how representative of any intentions that is. Is it just one guy working on one of the most widely used debugging extensions for PHP? For the most part , make sure to donate to support Derick's work if able! More on reddit.com
Videos
10:09
Setup Xdebug WITH DOCKER and debug in VSCode - YouTube
16:41
Tutoriel Xdebug/Docker/PHP : Xdebug avec PHP sous Docker - YouTube
09:32
Install xDebug 3 and PHP 8 in a Docker Container and Connect it ...
11:27
How To Install Xdebug 3 with Docker & PhpStorm - Full PHP 8 Tutorial ...
27:15
Debug PHP using Docker, VS Code, and XDebug - YouTube
06:32
Xdebug 3: Debugging the Symfony Demo App in Docker with VS Code ...
Top answer 1 of 3
11
RUN apk add --no-cache $PHPIZE_DEPS \
&& pecl install xdebug-2.9.2 \
&& docker-php-ext-enable xdebug \
2 of 3
3
I found this instructions here on how to set it up. Add it to the end of the php.dockerfile:
# Install base packages
RUN apk update
RUN apk upgrade
# xdebug with VSCODE
ENV XDEBUG_VERSION=2.9.2
RUN apk --no-cache add --virtual .build-deps \
g++ \
autoconf \
make && \
pecl install xdebug-${XDEBUG_VERSION} && \
docker-php-ext-enable xdebug && \
apk del .build-deps && \
rm -r /tmp/pear/* && \
echo -e "xdebug.remote_enable=1\n\
xdebug.remote_autostart=1\n\
xdebug.remote_connect_back=0\n\
xdebug.remote_port=9001\n\
xdebug.idekey=\"VSCODE\"\n\
xdebug.remote_log=/var/www/html/xdebug.log\n\
xdebug.remote_host=host.docker.internal" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
# Change TimeZone
RUN apk add --update tzdata
ENV TZ=Europe/Bucharest
EDIT: You should also remove the xdebug port in docker-compose.yml (In case you added it)
For **Visual Studio Code** Here is the kaunch.json I used:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"port": 9001,
"pathMappings": {
"/var/www/html/public": "${workspaceFolder}/src/public"
},
}
]
}
GitHub
github.com › sineverba › php74xc
GitHub - sineverba/php74xc: Docker image for PHP7.4 with Xdebug and Composer
Forked by 2 users
Languages Makefile 67.3% | Dockerfile 32.7% | Makefile 67.3% | Dockerfile 32.7%
Docker Hub
hub.docker.com › r › p1xel › ubuntu-php7-xdebug › dockerfile
p1xel/ubuntu-php7-xdebug Dockerfile
Welcome to the world's largest container registry built for developers and open source contributors to find, use, and share their container images. Build, push and pull.
Medium
medium.com › @adev95 › install-xdebug-for-php-7-on-docker-3e47b3e5de9c
Install XDebug for PHP 7 on Docker 🪲 | by Adev95 | Medium
October 3, 2023 - pecl channel-update pecl.php.net pecl install xdebug-2.7.2 \ && echo "zend_extension=$(find /usr/local/lib/php/extensions/ -name xdebug.so)" > /usr/local/etc/php/conf.d/xdebug.ini \ && echo "xdebug.remote_enable=on" >> /usr/local/etc/php/conf.d/xdebug.ini \ && echo "xdebug.remote_autostart=on" >> /usr/local/etc/php/conf.d/xdebug.ini \ && echo "xdebug.remote_host=host.docker.internal" >> /usr/local/etc/php/conf.d/xdebug.ini \ && echo "xdebug.remote_port=9596" >> /usr/local/etc/php/conf.d/xdebug.ini
GitHub
gist.github.com › chadrien › c90927ec2d160ffea9c4
Debug PHP in Docker with PHPStorm and Xdebug · GitHub
Hi, On linux with firewalld enabled, the container hasn't route for host, so it not attach to host port 9000 (xdebug). The route can be add by: firewall-cmd --zone=public --add-rich-rule='rule family="ipv4" source address="172.17.0.0/16" accept' Where 172.17.0.0 is docker container's subnet (check it with ifconfig). ... This will need to be updated for php 7.4, see: https://olvlvl.com/2019-06-install-php-ext-source , pecl won't be available in the php base image.
GitHub
github.com › mobtitude › docker-php-xdebug
GitHub - mobtitude/docker-php-xdebug: Docker images with PHP and xdebug installed, configured and ready to debug and profile applications in modern IDEs. · GitHub
Q: Why images don't have specific PHP version like 7.2.2 but only major and minor version 7.2? A: It is because images in this repo have always the newest possible patch version of PHP based on official Docker PHP images. For example for mobtitude/php-xdebug:7.2-apache you can expect that it is always the newest PHP version available in official Docker Registry and it is automatically updated when official PHP Docker images are updated.
Starred by 20 users
Forked by 8 users
Languages Dockerfile 61.9% | Shell 31.6% | Makefile 3.7% | PHP 2.8%
GitHub
github.com › maciejslawik › docker-php-fpm-xdebug › blob › master › Dockerfile
docker-php-fpm-xdebug/Dockerfile at master · maciejslawik/docker-php-fpm-xdebug
RUN echo 'alias xon="mv /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini.off /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini && kill -USR2 1"' >> ~/.bashrc · · # Change memory limit · RUN echo 'memory_limit = 2G ' >> /usr/local/etc/php/php.ini · · # Install Blackfire probe - no version for 7.4 available yet ·
Author maciejslawik
Peterbabic
peterbabic.com › blog › php-xdebug-in-docker
Peter Babič - PHP xDebug in Docker
February 23, 2025 - Whatever you Dockerfile contents are, add these somewhere sensible, before EXPOSE or COPY usually: RUN apk add --no-cache $PHPIZE_DEPS linux-headers && \ pecl install xdebug && docker-php-ext-enable xdebug
Matthew Setter
matthewsetter.com › setup-step-debugging-php-xdebug3-docker
Setup Step Debugging in PHP with Xdebug 3 and Docker Compose | Blog - Matthew Setter. Accessible Web App Developer, Educator, and Author, based in Bundaberg, Queensland.
March 10, 2021 - The php container uses a custom Dockerfile (./docker/php/Dockerfile) to define its build steps, which you can see in the example below. This is because Xdebug doesn't come "bundled" with the official Docker Hub PHP containers. FROM php:7.4-fpm RUN pecl install xdebug \ && docker-php-ext-enable xdebug
Stack Overflow
stackoverflow.com › questions › 73529501 › configure-xdebug-in-docker-container
php - Configure Xdebug in Docker container - Stack Overflow
My OS is Ubuntu 20.04.5 LTS; Dockerfile, docker-compose.yml and 90-xdebug.ini are in project's root. ... FROM php:7.4-apache COPY 90-xdebug.ini "/usr/local/etc/php/conf.d" RUN pecl install xdebug RUN docker-php-ext-enable xdebug
Docker
hub.docker.com › layers › lexasoft › apache-php-xdebug › 7.4 › images › sha256-e29330bde457a5116606c305c8a0c80b88014c11029c535f079416c3e1fbdaad
Image Layer Details - lexasoft/apache-php-xdebug:7.4
© 2026 Docker, Inc. All rights reserved. | Terms of Service | Subscription Service Agreement | Privacy | Legal
Docker
hub.docker.com › layers › lavoweb › php-7.4 › xdebug › images › sha256-39cb50ca60f5f05e798837afca32a6d7657e95e73d563f3115dd5aa722bafd99
Image Layer Details - lavoweb/php-7.4:xdebug
© 2026 Docker, Inc. All rights reserved. | Terms of Service | Subscription Service Agreement | Privacy | Legal
Thecodingmachine
thecodingmachine.io › configuring-xdebug-phpstorm-docker
Debugging PHP (web and cli) with Xdebug using Docker and PHPStorm
To follow this tutorial, you must have the Xdebug extension installed on your container. In my example, I will use a Docker image of TheCodingMachine created by David Négrier. If you are starting a project, I recommend you to download one of our images here TheCodingMachine Docker PHP images ... app: image: thecodingmachine/php:7.2-v1-apache volumes: - .:/var/www/html environment: PHP_EXTENSION_XDEBUG: 1