45

In order to resolve an issue, I am now trying install the mysql pdo via

docker-php-ext-install

as pointed out in the README of the php image.

Yet my call fails stating:

Libraries have been installed in:
   /usr/src/php/ext/mysqli/modules

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
   - add LIBDIR to the `LD_LIBRARY_PATH' environment variable
     during execution
   - add LIBDIR to the `LD_RUN_PATH' environment variable
     during linking
   - use the `-Wl,--rpath -Wl,LIBDIR' linker flag
   - have your system administrator add LIBDIR to `/etc/ld.so.conf'

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------

Build complete.
Don't forget to run 'make test'.

Installing shared extensions:     /usr/local/lib/php/extensions/no-debug-non-zts-20131226/
Installing header files:           /usr/local/include/php/
find . -name \*.gcno -o -name \*.gcda | xargs rm -f
find . -name \*.lo -o -name \*.o | xargs rm -f
find . -name \*.la -o -name \*.a | xargs rm -f 
find . -name \*.so | xargs rm -f
find . -name .libs -a -type d|xargs rm -rf
rm -f libphp.la       modules/* libs/*
+ 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 mysqli mysqlnd pdo pdo_mysql zip' returned a non-zero code: 1

This is 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'

This is 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 mysqli mysqlnd pdo pdo_mysql zip 

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

and running docker-compose build won't finish.

Community
  • 1
  • 1
k0pernikus
  • 60,309
  • 67
  • 216
  • 347

5 Answers5

23

I had the same problem a while ago. I started a container and typed the ext-install command into this container. Once I found all the dependencies, I wrote them into the Dockerfile.

Example:

RUN apt-get update && apt-get install -y \
libmcrypt-dev \
&& docker-php-ext-install -j$(nproc) mcrypt

There is a dependency that libmcrypt-dev needed before you can run docker-php-ext-install mcrypt

I've checked my older Dockerfiles and found something which might help you

FROM php:5.6-apache

RUN apt-get update && apt-get install -y \
        libfreetype6-dev \
        libjpeg62-turbo-dev \
        libmcrypt-dev \
        libpng12-dev \
    libicu-dev \
     libxml2-dev \
    vim \
        wget \
        unzip \
        git \
    && docker-php-ext-install -j$(nproc) iconv intl xml soap mcrypt opcache pdo pdo_mysql mysqli mbstring \
    && docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
    && docker-php-ext-install -j$(nproc) gd

RUN a2enmod rewrite && mkdir /composer-setup && wget https://getcomposer.org/installer -P /composer-setup && php /composer-setup/installer --install-dir=/usr/bin && rm -Rf /composer-setup && curl -LsS https://symfony.com/installer -o /usr/local/bin/symfony && chmod a+x /usr/local/bin/symfony
# Create symlink for default conf
RUN ln -s /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-enabled/000-default.conf && mkdir /composer-setup && wget https://getcomposer.org/installer -P /composer-setup && php /composer-setup/installer --install-dir=/usr/bin && rm -Rf /composer-setup && curl -LsS https://symfony.com/installer -o /usr/local/bin/symfony && chmod a+x /usr/local/bin/symfony
iamcastelli
  • 1,564
  • 2
  • 20
  • 30
Florian
  • 845
  • 1
  • 9
  • 17
  • 1
    Because of this, I tried running the docker-php-ext-install command inside the container instead of the Dockerfile after a build. And they work just fine there 0.o – k0pernikus May 30 '16 at 14:31
  • the Parameter -y is different in your config to mine. apt-get install -y instead of apt-get install vim git -y – Florian May 30 '16 at 19:55
12
RUN docker-php-ext-install mbstring pdo pdo_mysql \

That code can do install any extension you want in this case mysql pdp driver but the Dockerfile should have base of FROM php:7.1.8-apache

Richie
  • 570
  • 6
  • 10
  • 4
    The `php` images are missing a lot of build tools and dependencies, so you'll need to install the dependencies for building certain extensions yourself. Installing any extension is not as easy as just running `docker-php-ext-install` on them – padarom Mar 07 '19 at 08:23
7

The 2019 way and probably the 2020 way of installing memcached to your Docker PHP container is the way described on https://hub.docker.com/_/php

FROM php:latest
RUN pecl install memcached \
    && docker-php-ext-enable memcached
FROM php:5.6-cli
RUN apt-get update && apt-get install -y libmemcached-dev zlib1g-dev \
    && pecl install memcached-2.2.0 \
    && docker-php-ext-enable memcached
Daniel W.
  • 31,164
  • 13
  • 93
  • 151
  • 1
    Thanks, this helped me in 2021. To keep up to date, check the docker link, scroll down to "PECL extensions" – Mint Jul 20 '21 at 01:01
2

Alternatively, you can use this excellent helper to install the needed libs automatically for you.

https://github.com/mlocati/docker-php-extension-installer

You only need to list the extensions you want like this:

FROM php:8.2-fpm-alpine

ADD https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/

RUN chmod +x /usr/local/bin/install-php-extensions; \
    install-php-extensions mysqli mysqlnd pdo pdo_mysql zip 

Take a look at its GitHub page to see all options available to use.

Tales Santos
  • 232
  • 3
  • 10
1

Seems to be a bug in phpize (https://bugs.php.net/bug.php?id=53571).

I added the following to docker-php-ext-configure:

/usr/local/bin # diff -u docker-php-ext-configure.bak docker-php-ext-configure
--- docker-php-ext-configure.bak
+++ docker-php-ext-configure
@@ -54,5 +54,6 @@

 set -x
 cd "$ext"
+[[ ! -f "config.m4" && -f "config0.m4" ]] && mv config0.m4 config.m4
 phpize
 ./configure "$@"
Enrico Stahn
  • 2,967
  • 1
  • 23
  • 23