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
🌐
Docker Community
forums.docker.com › general
How to install xDebug on an php:alpine docker image? - General - Docker Community Forums
May 27, 2023 - 0 I am trying to install xDebug on a PHP Alpine Linux Docker image, and although xDebug is successfully installed for the CLI, phpinfo() on the web doesn’t report the extension loaded. I’m on Linux. How can I solve this? Here is the code: Dockerfile: FROM php:alpine RUN apk update && apk upgrade RUN apk add php-pear RUN apk add php-openssl RUN apk add bash RUN \ apk add --no-cache \ apache2-proxy \ apache2-ssl \ apache2-utils \ curl \ git \ logrotate \ ope...
🌐
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
🌐
GitHub
gist.github.com › patricknelson › 57ae24986cb13613314fb1f3c00a95d7
Using Xdebug in Docker (works with PhpStorm) · GitHub
# Installing Xdebug with PHP 7.3 images: RUN pecl install xdebug \ && docker-php-ext-enable xdebug
🌐
WPDiaries
wpdiaries.com › home › docker › how to add xdebug to the official docker wordpress image
How to Add XDebug to the Official Docker WordPress Image
November 16, 2025 - FROM wordpress:6.7.2-php8.4-apache # Install packages under Debian RUN apt-get update && \ apt-get -y install git # Install Xdebug from source as described here: # https://xdebug.org/docs/install # Available branches of Xdebug could be seen here: # https://github.com/xdebug/xdebug/branches RUN cd /tmp && \ git clone https://github.com/xdebug/xdebug.git && \ cd xdebug && \ git checkout xdebug_3_4 && \ phpize && \ ./configure --enable-xdebug && \ make && \ make install && \ rm -rf /tmp/xdebug # Copy xdebug.ini to /usr/local/etc/php/conf.d/ COPY files-to-copy/ / # Since this Dockerfile extends the official Docker image `wordpress`, # and since `wordpress`, in turn, extends the official Docker image `php`, # the helper script docker-php-ext-enable (defined for image `php`) # works here, and we can use it to enable xdebug: RUN docker-php-ext-enable xdebug
Find elsewhere
🌐
JetBrains
intellij-support.jetbrains.com › hc › en-us › community › posts › 8531104094994-Properly-setup-xdebug-with-PHP-Apache-Docker-Container-including-composer
Properly setup xdebug with PHP Apache Docker Container including composer – IDEs Support (IntelliJ Platform) | JetBrains
November 11, 2022 - FROM php:8.1-apache WORKDIR /var/www/html/ RUN pecl install xdebug \ && apt update \ && apt install libzip-dev -y \ && docker-php-ext-enable xdebug \ && a2enmod rewrite \ && docker-php-ext-install zip \ && rm -rf /var/lib/apt/lists/* COPY --from=composer:latest /usr/bin/composer /usr/bin/composer COPY composer.json .
🌐
Medium
medium.com › the-sensiolabs-tech-blog › how-to-use-xdebug-in-docker-phpstorm-76d998ef2534
How to use Xdebug in Docker & PhpStorm | The SensioLabs Tech Blog
June 14, 2022 - ... It is missing quite a few things ... Now let’s add Xdebug inthere · COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/bin/RUN install-php-extensions xdebug...
🌐
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 - We will demonstrate the setup with Laravel, PHP 8.4 and Xdebug v3.4.0, the latest stable versions at the time of writing. The gist of what we need to get Xdebug configured with a Docker image includes: A Dockerfile that installs the Xdebug module and configuration
🌐
GitHub
gist.github.com › chadrien › c90927ec2d160ffea9c4
Debug PHP in Docker with PHPStorm and Xdebug · GitHub
FROM php:5.6.38-apache RUN apt-get update &&\ apt-get install --no-install-recommends --assume-yes --quiet ca-certificates curl git telnet iputils-ping net-tools &&\ rm -rf /var/lib/apt/lists/* RUN pecl install xdebug-2.5.5 && docker-php-ext-enable xdebug \ && echo "zend_extension=$(find /usr/local/lib/php/extensions/ -name xdebug.so)" >> /usr/local/etc/php/php.ini \ && echo "xdebug.remote_port=9000" >> /usr/local/etc/php/php.ini \ && echo "xdebug.remote_enable=1" >> /usr/local/etc/php/php.ini \ && echo "xdebug.remote_connect_back=0" >> /usr/local/etc/php/php.ini \ && echo "xdebug.remote_host=docker.for.mac.localhost" >> /usr/local/etc/php/php.ini \ && echo "xdebug.idekey=IDEA_DEBUG" >> /usr/local/etc/php/php.ini \ && echo "xdebug.remote_autostart=1" >> /usr/local/etc/php/php.ini \ && echo "xdebug.remote_log=/tmp/xdebug.log" >> /usr/local/etc/php/php.ini
🌐
Medium
medium.com › @fico7489 › install-xdebug-in-your-docker-php-container-and-then-enable-and-disable-any-time-when-you-want-d8ac31ae53f4
Install “xdebug” in your docker PHP container and then enable and disable any time when you want | by Filip Horvat | Medium
February 20, 2023 - Finally, let’s go to install xdebug for you “app_php_dev” environment. Change “app_php_dev” part in Dockerfile with this: FROM app_php AS app_php_dev RUN echo 'app_php_dev' #add package for installing php extensions COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/local/bin/ #install xdebug RUN set -eux; install-php-extensions xdebug; #add some xdebug ini settings COPY xdebug.ini /tmp/xdebug.ini RUN cp /tmp/xdebug.ini /usr/local/etc/php/conf.d/xdebug.ini;
🌐
GitHub
github.com › mlocati › docker-php-extension-installer
GitHub - mlocati/docker-php-extension-installer: Easily install PHP extensions in Docker containers · GitHub
You may want to run docker pull ghcr.io/mlocati/php-extension-installer or docker pull mlocati/php-extension-installer in order to use an up-to-date version. Simply append -<version> to the module name.
Starred by 4.9K users
Forked by 430 users
Languages   Shell 84.3% | PHP 13.7% | JavaScript 1.6%
🌐
Viktor Babanov
viktorprogger.name › posts › xdebug-docker-config-example.html
An example of setting up xDebug in docker | Viktor Babanov
January 21, 2023 - RUN apk add --no-cache linux-headers \ && apk add --update --no-cache --virtual .build-dependencies $PHPIZE_DEPS\ && pecl install xdebug \ && docker-php-ext-enable xdebug \ && pecl clear-cache \ && apk del .build-dependencies
🌐
Heigl
andreas.heigl.org › home › xdebug in docker
Xdebug in Docker - andreas.heigl.org »
November 7, 2023 - FROM php:8.3-rc-fpm RUN PHPIZE_DEPS="autoconf \ cmake \ file \ g++ \ gcc \ libc-dev \ libpcre2-dev \ make \ git \ pkgconf \ re2c" \ && XDEBUG_VERSION="" \ && if [ "$(php -v | head -n 1 | grep 8.3)" != "" ]; then XDEBUG_VERSION="-3.3.0alpha3"; fi \ && apt-get update \ && apt-get install -y $PHPIZE_DEPS \ && pecl install xdebug${XDEBUG_VERSION} \ && docker-php-ext-enable xdebug \ && echo "xdebug.mode=debug\nxdebug.discover_client_host=on\nxdebug.start_with_request=yes\nxdebug.log_level=0" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \ && apt-get remove -y $PHPIZE_DEPS
🌐
GitHub
github.com › maciejslawik › docker-php-fpm-xdebug › blob › master › Dockerfile
docker-php-fpm-xdebug/Dockerfile at master · maciejslawik/docker-php-fpm-xdebug
RUN pecl install xdebug-2.9.1 \ && docker-php-ext-enable xdebug \ && echo "error_reporting = E_ALL" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \ && echo "display_startup_errors = On" >> /usr/local/etc/php/conf.d/dock...
Author   maciejslawik
🌐
Reddit
reddit.com › r/phphelp › help to get php8 w/ xdebug in docker on osx running for local dev (phpunit) via phpstorm in a checkout project
r/PHPhelp on Reddit: Help to get PHP8 w/ xdebug in Docker on OSX running for local dev (phpunit) via PhpStorm in a checkout project
November 14, 2020 -

SOLVED

See https://www.reddit.com/r/PHPhelp/comments/jti8i2/help_to_get_php8_w_xdebug_in_docker_on_osx/gc7g8j5/?utm_source=reddit&utm_medium=web2x&context=3 for the summary

Thanks everyone!


I've never really used docker before and I'm hitting so many walls that I stopped counting, I think today (Friday 13th) is my lucky day.

What I currently have:

  • Host OSX

  • PHP 7.4 installed via brew

  • git clone of my project

  • phpunit tests are running, also inside PhpStorm

  • I can also debug, I've xdebug installed via pecl

What I'm trying to achieve:

  • same as above but with PHP 8 without replacing my brew PHP 7.4; this is intended only for local dev

  • I don't need webserver etc., just CLI

  • PHP 8.0 (e.g. the php:8.0.0RC4-cli image I guess?)

  • being able to install the composer dependencies via PHP within docker, important for package version resolving (this project will install different version on different PHP version to be compatible)

  • run phpunit (ideally also via PhpStorm)

  • super bonus: also get xdebug working in the docker image (probably need to add further install steps with pecl in Dockerfile?) so it also works via PhpStorm

In fact, I don't know how, I got it working that I can run phpunit and it runs it in the docker image; but I'm too stupid to figure out how to also run composer inside the image. I don't even know of composer is available in this image 🤷‍♀️

Dockerfile I have (don't laugh):

FROM php:8.0.0RC4-cli

ADD ./ /app

WORKDIR /app

Docker composer (because no idea, tutorials and stuff):

version: '3'

services:
    php:
        build: .
        volumes:
            - ./:/app
        working_dir: '/app'

I then did docker-compose build and the resulting image I selected in PhpStorm (remote interpreter) and managed to get phpunit running.

It "works" but the vendor files are still from my local host PHP composer installation and they contain incompatible code with PHP8 (e.g. classes like Match 💥), thus I need fix that but no idea (aka run composer in Docker with PHP 8).

Is anyone willing / has the energy and time to help me moving forward? Would be much appreciated :)

Thanks

🌐
JetBrains
jetbrains.com › help › phpstorm › configuring-xdebug.html
Configure Xdebug | PhpStorm Documentation
In this example, we're modifying /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini providing the remote_enable and remote_host Xdebug parameters.