How to install extension for php via docker-php-ext-install?

后端 未结 5 813
再見小時候
再見小時候 2020-12-28 13:40

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 imag

相关标签:
5条回答
  • 2020-12-28 13:46

    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
    
    0 讨论(0)
  • 2020-12-28 13:49

    You can achieve this with only 3 short lines of code. Here is an example for PHP7.4-FPM (Check the attached github link for guidance on other image variants and versions)

    Dockerfile:

    FROM php:7.4-fpm
    
    COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/bin/
    
    RUN install-php-extensions mysqli pdo_mysql
    

    As of the posting of this response the plugin supports up to 80 PHP Extensions which I find it supper amazing. You can get more info on this github repository

    0 讨论(0)
  • 2020-12-28 13:52
    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

    0 讨论(0)
  • 2020-12-28 14:03

    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 "$@"
    
    0 讨论(0)
  • 2020-12-28 14:04

    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
    
    0 讨论(0)
提交回复
热议问题