Php: Enabling xdebug produces error

Created on 2 May 2017  路  6Comments  路  Source: docker-library/php

Here is Dockerfile:
````
FROM php:7.1-fpm-alpine
MAINTAINER effio web studio info@effio.org

Runtime dependencies

ENV PHPIZE_DEPS \
autoconf \
file \
g++ \
gcc \
libc-dev \
make \
pkgconf \
re2c

RUN set -xe \
&& apk add --no-cache bash bash-completion coreutils \
&& apk add --no-cache --virtual .persistent-deps \
freetype \
libjpeg-turbo \
libpng \
icu-libs \
libmcrypt \
libltdl \
libxml2 \
libpq \
&& apk add --no-cache --virtual .build-deps \
$PHPIZE_DEPS \
freetype-dev \
libjpeg-turbo-dev \
libpng-dev \
icu-dev \
libmcrypt-dev \
libxml2-dev \
mariadb-client-libs \
postgresql-dev \
&& docker-php-ext-install -j$(nproc) zip \
&& docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ --with-png-dir=/usr/include/ \
&& docker-php-ext-install -j$(nproc) gd \
&& docker-php-ext-configure bcmath \
&& docker-php-ext-install -j$(nproc) \
bcmath \
exif \
intl \
mcrypt \
pdo_mysql \
pdo_pgsql \
soap \
&& pecl channel-update pecl.php.net \
&& printf "\n" | pecl install apcu xdebug imagick \
&& apk del .build-deps

WORKDIR /app

COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
CMD ["php-fpm"]
````

And here is entrypoint.sh (which simply checks if there is PHP_ENABLE_XDEBUG environment variables, it enables xdebug:
````

!/bin/bash

set -e

If PHP_ENABLE_XDEBUG=1 xdebug extension will be enabled

[ -n "$PHP_ENABLE_XDEBUG" ] && docker-php-ext-enable xdebug

Execute CMD

exec "$@"
````

But when passing PHP_ENABLE_XDEBUG variable to the container and running php --version in it, I get following error:
/usr/local/bin/docker-php-ext-enable: line 83: nm: not found PHP Warning: Xdebug MUST be loaded as a Zend extension in Unknown on line 0

I think there's some lib dependency that is removed (purged) with my build dependencies.

All 6 comments

There was also the same issue before, which was closed by author without correct solution.

Also this issue is related or duplicate. I suggest installing binutils as persistent dependency, will you accept PR with such changes?

Have the same problem, but strangely it's not interrupting xdebug. To fix "nm not found" line I just installed binutils and error has gone.

The purpose of the alpine based images are to be as small as possible for the end use case. If we add binutils, which is not required to run php, it would be unused space that cannot be reclaimed (almost a 16% increase from the current size, so 9.1MB).

For alpine based images I would instead follow the recommendation to "add the things you need in your own Dockerfile", that way you can choose to remove them in the same layer they are used or to keep them around.

I completely agree on this question, it would be just great to mention it somewhere in documentation.

Was this page helpful?
0 / 5 - 0 ratings