Hasina Njaratin
Hasina Njaratin

Reputation: 481

Docker Enable Xdebug

I have such Dockerfile for my php-container:

FROM my-image/debian

ARG PHP_VERSION

...
...

RUN \
    set -eux \
    \
    # INSTALL SURY SOURCES
    && buildDeps='apt-transport-https lsb-release wget' \
    && apt-get update \
    && apt-get install -y --no-install-recommends --no-install-suggests $buildDeps \
    && wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg \
    && echo "deb https://packages.sury.org/php/ buster main" > /etc/apt/sources.list.d/php.list \
    \
    && update-ca-certificates \
    \
    # INSTALL PHP PACKAGES
    && apt-get update \
    && apt-get install -y --no-install-recommends --no-install-suggests \
      php$PHP_VERSION \
      php$PHP_VERSION-cli \
      php$PHP_VERSION-fpm \
      php$PHP_VERSION-opcache \
      php$PHP_VERSION-redis \
      php$PHP_VERSION-apcu \
      php$PHP_VERSION-zip zip unzip \
      php$PHP_VERSION-curl \
      php$PHP_VERSION-gd \
      php$PHP_VERSION-intl \
      php$PHP_VERSION-mysql \
      php$PHP_VERSION-soap \
      php$PHP_VERSION-amqp \
      php$PHP_VERSION-bcmath \
      php$PHP_VERSION-socket \
      php$PHP_VERSION-dom \
      php$PHP_VERSION-mbstring \
      php-pear \
      php$PHP_VERSION-dev \
    && mkdir -p /var/run/ \
    \
    # Install xdebug
    && pecl install xdebug \
    && docker-php-ext-enable xdebug \
    \
    # CLEAN
    && apt-get clean \
    && apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false $buildDeps \
    && rm -rf /var/lib/apt/lists/* \
    && rm -rf /var/cache/apt/archives/* \
    && rm -rf /tmp/* \
....
....
....

when I build it, i get error /bin/sh: 1: docker-php-ext-enable: not found

I don't want to get image from alpine or other external php image. Cause particular reasons, i want to build php and have an hand from my-image/debian.

Could someone help me activate xdebug? It is well installed (via the pecl) but when I do php -v it is not there, even after rebuild and restart of the containers

Thanks

Upvotes: 0

Views: 1687

Answers (2)

studio1057
studio1057

Reputation: 157

...Dockerfile #Install Xdebug

RUN PECL INSTALL xdebug \

&& docker-php-ext-enable xdebug

RUN chown notroot:notroot \

/<path in docker container for dockerphp--ext-xdebug.ini

...docker-compose.yml

`volumes:
    - ./<path to local docker-php-ext-xdebug.ini>:/<path to docker docker-php-xdebug.ini`

Prerequisites: You nned to have pecl installed previousy (higher in the Dockerfile)

Upvotes: 0

Alexander Yancharuk
Alexander Yancharuk

Reputation: 14531

Script docker-php-ext-enable by default does not exists in Debian images. You need co copy it into your docker-image like in official 7.3 buster image. Add to your Dockerfile string:

....
COPY docker-php-ext-enable /usr/local/bin/
....
    && docker-php-ext-enable xdebug \
....

Don't forget to place docker-php-ext-enable file into build-context dir.

Upvotes: 1

Related Questions