php: docker-php-ext-install fails with phpize not finding config.m4

(I wrote a question on stackoverflow about it, but I guess it fits more here.)

My Dockerfile:

FROM php:5.6-apache

RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" && \
    php -r "if (hash_file('SHA384', 'composer-setup.php') === '070854512ef404f16bac87071a6db9fd9721da1684cd4589b1196c3faf71b9a2682e2311b36a5079825e155ac7ce150d') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" && \
    php composer-setup.php && \
    php -r "unlink('composer-setup.php');"


RUN apt-get update && \
    apt-get install vim git -y
RUN docker-php-ext-install mysqlnd pdo pdo_mysql

RUN  cd /  && \
    git clone --depth=1 git://github.com/phalcon/cphalcon.git && \
    cd cphalcon/build && \
    ./install

RUN echo "extension=phalcon.so" > /usr/local/etc/php/conf.d/phalcon.ini
RUN a2enmod rewrite

My docker-compose.yml:

phlaconapp:
    hostname: phaclonapp
    dockerfile: Dockerfile
    build: ./
    ports:
        - "1080:80"
        - "1043:433"
    environment:
        TERM: xterm-color
        ENVIRONMENT: dev
    volumes:
        - ./:/var/www/html/
    links:
        - mysql
mysql:
    image: mysql:5.6
    volumes:
        - ./docker/mysql.d:/etc/mysql/conf.d
    ports: ["3306:3306"]
    environment:
        MYSQL_ROOT_PASSWORD: 'root'

Yet when running docker-compose build I get:

\mysql uses an image, skipping
Building phlaconapp
Step 1 : FROM php:5.6-apache
 ---> 2dd2b6f11998
Step 2 : RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" &&     php -r "if (hash_file('SHA384', 'composer-setup.php') === '070854512ef404f16bac87071a6db9fd9721da1684cd4589b1196c3faf71b9a2682e2311b36a5079825e155ac7ce150d') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" &&     php composer-setup.php &&     php -r "unlink('composer-setup.php');"
 ---> Using cache
 ---> be0059709c8b
Step 3 : RUN apt-get update &&     apt-get install vim git -y
 ---> Using cache
 ---> 64cc739633c9
Step 4 : RUN docker-php-ext-install mysqlnd pdo pdo_mysql
 ---> Running in 8587aeb52c5b
+ cd /usr/src/php/ext/mysqlnd
+ phpize
Cannot find config.m4. 
Make sure that you run '/usr/local/bin/phpize' in the top level source directory of the module

ERROR: Service 'phlaconapp' failed to build: The command '/bin/sh -c docker-php-ext-install mysqlnd pdo pdo_mysql' returned a non-zero code: 1

How am I supposed to install extension with docker-php-ext-install?

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 7
  • Comments: 21 (4 by maintainers)

Commits related to this issue

Most upvoted comments

Another Quick-And-Dirty solution for “phpize, Cannot find config.m4.”:

#First we try to install your extension, it will fail here so force exit code 0 to keep Dockerfile processing. #We do this to have the extension files downloaded for step 2 RUN docker-php-ext-install zlib; exit 0 #Now we rename the in step 1 downloaded file to desired filename RUN cp /usr/src/php/ext/zlib/config0.m4 /usr/src/php/ext/zlib/config.m4 #And try to install extension again, this time it works RUN docker-php-ext-install zlib

Any ideas when this will be fixed? Still having this issue with latest php:7.2-rc-fpm-alpine.

Removing the docker-php-ext-install zlib from the docker fixed for me

@chrBrd, openssl and a few other modules are built with php and do not require docker-php-ext* scripts: https://github.com/docker-library/php/blob/d8d798be28c49ced47d772aa899c0a1febabdba3/7.1/alpine3.4/fpm/Dockerfile#L116-L132

You can even verify that it is available:

$ docker run --rm php:7-fpm-alpine php -i | grep -i ssl
Configure Command =>  './configure'  '--build=x86_64-linux-musl' '--with-config-file-path=/usr/local/etc/php' '--with-config-file-scan-dir=/usr/local/etc/php/conf.d' '--disable-cgi' '--enable-ftp' '--enable-mbstring' '--enable-mysqlnd' '--with-curl' '--with-libedit' '--with-openssl' '--with-zlib' '--with-pcre-regex=/usr' '--enable-fpm' '--with-fpm-user=www-data' '--with-fpm-group=www-data' 'build_alias=x86_64-linux-musl'
Registered Stream Socket Transports => tcp, udp, unix, udg, ssl, sslv3, tls, tlsv1.0, tlsv1.1, tlsv1.2
SSL => Yes
SSL Version => OpenSSL/1.0.2k
core SSL => supported
extended SSL => supported
openssl
OpenSSL support => enabled
OpenSSL Library Version => OpenSSL 1.0.2k  26 Jan 2017
OpenSSL Header Version => OpenSSL 1.0.2k  26 Jan 2017
Openssl default config => /etc/ssl/openssl.cnf
openssl.cafile => no value => no value
openssl.capath => no value => no value
Native OpenSSL support => enabled

For me it failed couple times trying to install other extensions like zlib openssl, but these were already included in the base image when I ran phpinfo. Also I’m using @michaellopez workaround and it worked just fine. on php:7.1.7-fpm-alpine

Dockerfile

FROM php:7.1.7-fpm-alpine
WORKDIR /usr/share/nginx/html
RUN apk --no-cache add --virtual .build-deps $PHPIZE_DEPS \
  && apk --no-cache add --virtual .ext-deps libmcrypt-dev freetype-dev \
  libjpeg-turbo-dev libpng-dev libxml2-dev msmtp postgresql-dev \
  && docker-php-source extract \
  && docker-php-ext-configure gd --with-freetype-dir=/usr/include/ \
                                   --with-png-dir=/usr/include/ \
                                   --with-jpeg-dir=/usr/include/ \
  && docker-php-ext-install gd mcrypt mysqli pdo pdo_mysql pdo_pgsql pgsql zip ftp opcache \
  && pecl install mongodb redis xdebug \
  && docker-php-ext-enable mongodb \
  && docker-php-ext-enable redis \
  && docker-php-ext-enable xdebug \
  && docker-php-source delete \
  && apk del .build-deps \
  # composer taken from (https://github.com/geshan/docker-php-composer-alpine)
  && apk --no-cache add curl git openssh \
  && curl -sSL https://getcomposer.org/installer | php -- --install-dir=/usr/bin --filename=composer

My current workaround is not looking very nice:

RUN ...
    && apk add --no-cache --virtual .phpize-deps $PHPIZE_DEPS \
    && docker-php-ext-configure gd --with-png-dir=/usr/include --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
    && apk del .phpize-deps \

Note that apk add --no-cache --virtual .phpize-deps $PHPIZE_DEPS \ is needed after each docker-php-ext-install call as that script removes the dependencies…

Still affecting php:7.4-fpm-alpine but skipping installation of extensions that are already included in the image seems to avoid the issue.

Still doesn’t work. sqlite3 has config0.m4 so phpize doesn’t manage to build the extension. How it supposed to work?

Removing docker-php-ext-install zlib fix the issue with php:7.3-fpm-alpine.

If you take a look here, the extension is already installed.