Search code examples
phpdockerxdebug-3

How to fix docker-php-ext-enable: not found when Dockerfile is FROM debian:10?


I want to upgrade to xdebug 3, currently there is installed xdebug 2.

The Dockerfile stars with

FROM debian:10

I have added line

RUN pecl install xdebug && docker-php-ext-enable xdebug

and I get error when building:

Installing '/usr/lib/php/20170718/xdebug.so'
install ok: channel://pecl.php.net/xdebug-3.1.5
configuration option "php_ini" is not set to php.ini location
You should add "zend_extension=/usr/lib/php/20170718/xdebug.so" to php.ini
/bin/sh: 1: docker-php-ext-enable: not found
The command '/bin/sh -c pecl install xdebug && docker-php-ext-enable xdebug' returned a non-zero code: 127

The part about xdebug.so is not in red color. But docker-php-ext-enable: not found is in red. So I am not sure why it writes that I should add xdebug.so but not in red.

But there is also a file docker/apache/conf/php/xdebug/20-xdebug.ini which was used for xdebug 2 and there is a line

zend_extension=xdebug.so

so again not clear why it writes to add it.

Also tried:

docker-compose build --no-cache

but getting same error

/bin/sh: 1: docker-php-ext-enable: not found

I have tried this snippet also to install xdebug 3

RUN apk add --no-cache --virtual .build-deps $PHPIZE_DEPS && \
    pecl install xdebug && \
    docker-php-ext-enable xdebug && \
    printf "xdebug.mode=develop,debug \n\
          xdebug.client_host=host.docker.internal \n\
          xdebug.start_with_request=yes \n" >> /etc/php/$PHP_VERSION/cli/conf.d/20-xdebug.ini && \
    apk del .build-deps && \
    rm -Rf /tmp/*

but it did not work probably because of debian and I do not know how to fix that. Just as long as I can install xdebug 3 and enable, I am fine with the solution. Looks like need to change

RUN apk add --no-cache --virtual .build-deps $PHPIZE_DEPS

but not sure how.


Solution

  • As mentioned, use the Debian package manager

    FROM debian:10
    sudo apt-get install php-xdebug
    

    Note that

    For packages that have the PHP version in the package name, such as in php81-php-xdebug3, you can substitute the PHP version with the one that matches the PHP version that you are running.

    And, warning

    If the package manager installs a version that is no longer supported (see Supported Versions), please install Xdebug with PECL, or from source instead.

    pecl install xdebug
    

    xdebug install