How to install php-redis extension using the official PHP Docker image approach?

前端 未结 11 1048
Happy的楠姐
Happy的楠姐 2021-01-30 02:21

I want to build my PHP-FPM image with php-redis extension based on the official PHP Docker image, for example, using this Dockerfile: php:5.6-fpm.

The docs

11条回答
  •  终归单人心
    2021-01-30 02:38

    I've found two ways to install php-redis extension for official php-fpm Docker image. Here they are:

    The first way is to compile redis from sources and install.

    RUN curl -L -o /tmp/redis.tar.gz https://github.com/phpredis/phpredis/archive/2.2.7.tar.gz \
        && tar xfz /tmp/redis.tar.gz \
        && rm -r /tmp/redis.tar.gz \
        && mv phpredis-2.2.7 /usr/src/php/ext/redis \
        && docker-php-ext-install redis
    

    docker-php-ext-install script is included in php-fpm image and can compile extensions and install them.

    The second way you can do it is with PECL.

    As TimWolla answered, you can do it with PECL, but in my case, PECL isn't installed by default.

    RUN pecl install -o -f redis \
    &&  rm -rf /tmp/pear \
    &&  echo "extension=redis.so" > /usr/local/etc/php/conf.d/redis.ini
    

提交回复
热议问题