Xdebug traffic wasn't finding it's way back to my host. When I entered the IP-address of my host machine in xdebug.remote_host, debugging worked but this was not ideal because my IP changes on every reboot. Luckily, Docker provides a way to obtain the host IP via a DNS-entry docker.for.win.localhost.

Edit:
Docker now has a platform-independent DNS-entry host.docker.internal.

I tried to use xdebug.remote_connect_back=1 which just responds to traffic from where it came but it wasn't working. Phpinfo() showed that REMOTE_ADDR was set to localhost. Localhost in this context points to the Docker PHP-container while it should point to our host IP. Important to know with this setting is that xdebug.remote_host in the .ini will be ignored.

From the Xdebug docs:

xdebug.remote_connect_back Type: boolean, Default value: 0, Introduced in Xdebug >= 2.1

If enabled, the xdebug.remote_host setting is ignored and Xdebug will try to connect to the client that made the HTTP request.

Here is the Dockerfile with the xdebug.ini configuration for the PHP Docker container that worked:

FROM php:7.1-fpm
ARG TIMEZONE

MAINTAINER Maxence POUTORD <[email protected]>

RUN apt-get update && apt-get install -y \
    openssl \
    git \
    unzip

# Install Composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
RUN composer --version

# Set timezone
RUN ln -snf /usr/share/zoneinfo/${TIMEZONE} /etc/localtime && echo ${TIMEZONE} > /etc/timezone
RUN printf '[PHP]\ndate.timezone = "%s"\n', ${TIMEZONE} > /usr/local/etc/php/conf.d/tzone.ini
RUN "date"

# Type docker-php-ext-install to see available extensions
RUN docker-php-ext-install pdo pdo_mysql

# install xdebug
RUN pecl install xdebug
RUN docker-php-ext-enable xdebug
RUN echo "zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20160303/xdebug.so" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
RUN echo "error_reporting = E_ALL" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
RUN echo "display_startup_errors = On" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
RUN echo "display_errors = On" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini

# relevant to this answer
RUN echo "xdebug.idekey=\"PHPSTORM\"" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
RUN echo "xdebug.remote_port=9000" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
RUN echo "xdebug.remote_enable=1" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
RUN echo "xdebug.remote_autostart=1" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
RUN echo "xdebug.remote_host=docker.for.win.localhost" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini

RUN echo 'alias sf="php app/console"' >> ~/.bashrc
RUN echo 'alias sf3="php bin/console"' >> ~/.bashrc

WORKDIR /var/www/free-energy/symfony


Edit:
I was messing around with XDebug quite a bit in this post.
Now I know your XDebug config doesn't have to be as big as I had back then.

xdebug.ini: (in your Docker PHP image).

zend_extension=xdebug.so

[Xdebug]
xdebug.remote_enable=true
xdebug.remote_port=9000
xdebug.remote_host=host.docker.internal
Answer from progonkpa on Stack Overflow
Top answer
1 of 2
10

Xdebug traffic wasn't finding it's way back to my host. When I entered the IP-address of my host machine in xdebug.remote_host, debugging worked but this was not ideal because my IP changes on every reboot. Luckily, Docker provides a way to obtain the host IP via a DNS-entry docker.for.win.localhost.

Edit:
Docker now has a platform-independent DNS-entry host.docker.internal.

I tried to use xdebug.remote_connect_back=1 which just responds to traffic from where it came but it wasn't working. Phpinfo() showed that REMOTE_ADDR was set to localhost. Localhost in this context points to the Docker PHP-container while it should point to our host IP. Important to know with this setting is that xdebug.remote_host in the .ini will be ignored.

From the Xdebug docs:

xdebug.remote_connect_back Type: boolean, Default value: 0, Introduced in Xdebug >= 2.1

If enabled, the xdebug.remote_host setting is ignored and Xdebug will try to connect to the client that made the HTTP request.

Here is the Dockerfile with the xdebug.ini configuration for the PHP Docker container that worked:

FROM php:7.1-fpm
ARG TIMEZONE

MAINTAINER Maxence POUTORD <[email protected]>

RUN apt-get update && apt-get install -y \
    openssl \
    git \
    unzip

# Install Composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
RUN composer --version

# Set timezone
RUN ln -snf /usr/share/zoneinfo/${TIMEZONE} /etc/localtime && echo ${TIMEZONE} > /etc/timezone
RUN printf '[PHP]\ndate.timezone = "%s"\n', ${TIMEZONE} > /usr/local/etc/php/conf.d/tzone.ini
RUN "date"

# Type docker-php-ext-install to see available extensions
RUN docker-php-ext-install pdo pdo_mysql

# install xdebug
RUN pecl install xdebug
RUN docker-php-ext-enable xdebug
RUN echo "zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20160303/xdebug.so" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
RUN echo "error_reporting = E_ALL" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
RUN echo "display_startup_errors = On" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
RUN echo "display_errors = On" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini

# relevant to this answer
RUN echo "xdebug.idekey=\"PHPSTORM\"" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
RUN echo "xdebug.remote_port=9000" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
RUN echo "xdebug.remote_enable=1" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
RUN echo "xdebug.remote_autostart=1" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
RUN echo "xdebug.remote_host=docker.for.win.localhost" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini

RUN echo 'alias sf="php app/console"' >> ~/.bashrc
RUN echo 'alias sf3="php bin/console"' >> ~/.bashrc

WORKDIR /var/www/free-energy/symfony


Edit:
I was messing around with XDebug quite a bit in this post.
Now I know your XDebug config doesn't have to be as big as I had back then.

xdebug.ini: (in your Docker PHP image).

zend_extension=xdebug.so

[Xdebug]
xdebug.remote_enable=true
xdebug.remote_port=9000
xdebug.remote_host=host.docker.internal
2 of 2
1

Add the remote_connect_back=on, so xdebug connects to the current visitor (using the REMOTE_ADDR system variable) instead of the remote_host which may change. You can try with remote_autostart=on too, to make sure this issue is not related with the browser itself.

Remember to configure the mapping in phpStorm as well, but it will tell you to do so anyway. Also make sure the IDE is listening to the debug session (small toggle in the debug toolbar). Good luck.

🌐
GitHub
github.com › maciejslawik › docker-php-fpm-xdebug
GitHub - maciejslawik/docker-php-fpm-xdebug: Docker image: PHP-FPM with XDEBUG enabled.
The repository stores an image of PHP-FPM (5.6-7.4) with preconfigured XDEBUG for local development.
Starred by 25 users
Forked by 12 users
Languages   Dockerfile 100.0% | Dockerfile 100.0%
🌐
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 xoff="mv /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini.off && kill -USR2 1"' >> ~/.bashrc
Author   maciejslawik
🌐
GitHub
github.com › serversideup › docker-php › discussions › 176
Xdebug with fpm-nginx · serversideup/docker-php · Discussion #176
Now that install-php-extensions is included in the v3 image, I use this much simpler fpm-nginx_xdebug.dockerfile : ARG PHP_VERSION FROM serversideup/php:${PHP_VERSION}-fpm-nginx USER root RUN install-php-extensions gd xdebug RUN echo "xdebug.mode=debug" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \ && echo "xdebug.start_with_request=trigger" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \ && echo "xdebug.trigger_value=PHPSTORM" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \ && echo "xdebug.client_port=9003" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \ && echo "xdebug.client_host=host.docker.internal" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini # Expose port 9003 for Xdebug EXPOSE 9003 USER www-data
Author   serversideup
🌐
Peterbabic
peterbabic.com › blog › php-xdebug-in-docker
Peter Babič - PHP xDebug in Docker
February 23, 2025 - RUN apk add --no-cache $PHPIZE_DEPS linux-headers && \ pecl install xdebug && docker-php-ext-enable xdebug · Base for the docker-compose.yml is below. Note the .ini files in volumes: version: "3.9" services: app: build: context: ./ dockerfile: Dockerfile image: php-fpm-81 container_name: my-app restart: unless-stopped tty: true working_dir: /var/www volumes: - ./:/var/www - ./docker/php/conf.d/xdebug.ini:/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini - ./docker/php/conf.d/error_reporting.ini:/usr/local/etc/php/conf.d/error_reporting.ini
🌐
Laravel News
laravel-news.com › home › laravel tutorials › get xdebug working with docker and php 8.4 in one minute
Get Xdebug Working With Docker and PHP 8.4 in One Minute - Laravel News
December 31, 2024 - In this post, we are going to use Apache to simplify the server setup; however, the Dockerfile code is identical to configuring Xdebug in a PHP-FPM image.
🌐
Docker Hub
hub.docker.com › r › dgtlmoon › php-5.6-fpm-xdebug › dockerfile
Dockerfile - dgtlmoon/php-5.6-fpm-xdebug
© 2025 Docker, Inc. All rights reserved. | Terms of Service | Subscription Service Agreement | Privacy | Legal
Find elsewhere
🌐
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 - 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
🌐
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
mobtitude/php-xdebug:8.4-fpm · Deprecated tags (they are available in docker hub, but no further updates will be provided): mobtitude/php-xdebug:5.6-apache · mobtitude/php-xdebug:5.6-cli · mobtitude/php-xdebug:5.6-fpm · mobtitude/php-xdebug:7.0-apache · mobtitude/php-xdebug:7.0-cli ·
Starred by 20 users
Forked by 8 users
Languages   Dockerfile 61.9% | Shell 31.6% | Makefile 3.7% | PHP 2.8%
🌐
GitHub
github.com › ionut-botizan › docker-nginx-php-xdebug
GitHub - ionut-botizan/docker-nginx-php-xdebug: A basic Docker setup, with zero initial configuration, for a development environment using Docker, Nginx, PHP-FPM, Xdebug.
A basic Docker setup, with zero initial configuration, for a development environment using Docker, Nginx, PHP-FPM, Xdebug. - ionut-botizan/docker-nginx-php-xdebug
Starred by 18 users
Forked by 11 users
Languages   PHP 100.0% | PHP 100.0%
🌐
DEV Community
dev.to › pimenvibritania › debug-docker-php-project-on-phpstorm-using-xdebug-224f
Debug Docker PHP Project on PHPStorm using Xdebug - DEV Community
December 4, 2021 - FROM php:8.1.0-fpm ADD https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/ RUN apt-get update && apt-get install -y \ git \ curl \ zip \ nano \ vim \ unzip RUN chmod +x /usr/local/bin/install-php-extensions && \ install-php-extensions gd xdebug pdo-mysql RUN docker-php-ext-install pdo pdo_mysql RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" RUN php composer-setup.php --install-dir=. --filename=composer RUN mv composer /usr/local/bin/ COPY ../ /var/www/ WORKDIR /var/www EXPOSE 9000
🌐
Docker Hub
hub.docker.com › r › andrdru › php-fpm-xdebug
Docker
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.
🌐
GitHub
github.com › IshtarStar › docker-compose-nginx-phpfpm-xdebug-mariadb
GitHub - IshtarStar/docker-compose-nginx-phpfpm-xdebug-mariadb: The primary goal of this project is to create a streamlined and efficient development environment using Docker Compose. This environment will consist of PHP-FPM, Xdebug, Nginx web server, and MariaDB, enabling developers to quickly and easily start working on their PHP projects. · GitHub
The primary goal of this project is to create a streamlined and efficient development environment using Docker Compose. This environment will consist of PHP-FPM, Xdebug, Nginx web server, and MariaDB, enabling developers to quickly and easily ...
Starred by 48 users
Forked by 23 users
Languages   Dockerfile 67.7% | PHP 32.3%
🌐
DEV Community
dev.to › _mertsimsek › using-xdebug-with-docker-2k8o
Using Xdebug with Docker - DEV Community
April 8, 2019 - FROM php:7.2-fpm-alpine RUN apk update \ && apk add --no-cache git mysql-client curl libmcrypt libmcrypt-dev openssh-client icu-dev \ libxml2-dev freetype-dev libpng-dev libjpeg-turbo-dev g++ make autoconf \ && docker-php-source extract \ && pecl install xdebug redis \ && docker-php-ext-enable xdebug redis \ && docker-php-source delete \ && docker-php-ext-install pdo_mysql soap intl zip \ && echo "xdebug.remote_enable=on" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \ && echo "xdebug.remote_autostart=off" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \ && echo "xdebug.remote
🌐
Thecodingmachine
thecodingmachine.io › configuring-xdebug-phpstorm-docker
Debugging PHP (web and cli) with Xdebug using Docker and PHPStorm
Our PHP container has Xdebug installed and Xdebug will try to connect to PHPStorm on port 9000 by default. Out of the box, everything should be fine... ... except if port 9000 is already taken by another program on your host (your machine running PHPStorm). Port 9000 can be already used. In particular, if you are using PHP-FPM, the default port for PHP-FPM is 9000.