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
Slightly revised version of starikovs and skyred answers for current version of the docker image. Tested on php:5-fpm-alpine
# install phpredis extension
ENV PHPREDIS_VERSION 2.2.8
ADD https://github.com/phpredis/phpredis/archive/$PHPREDIS_VERSION.tar.gz /tmp/redis.tar.gz
RUN tar xzf /tmp/redis.tar.gz -C /tmp \
&& mkdir -p /usr/src/php/ext \
&& mv /tmp/phpredis-$PHPREDIS_VERSION /usr/src/php/ext/redis \
&& echo 'redis' >> /usr/src/php-available-exts \
&& docker-php-ext-install redis \
&& rm -rf /usr/src/php/ext/redis
I'm using combination of PECL and PHP official docker extension script
RUN pecl bundle -d /usr/src/php/ext redis \
&& rm /usr/src/php/ext/redis-*.tgz \
&& docker-php-ext-install redis
For PHP7 you need to wait for official redis pecl release or use git:
RUN apt-get update \
&& apt-get install git -y -q \
&& git clone -b php7 https://github.com/phpredis/phpredis.git /usr/src/php/ext/redis \
&& docker-php-ext-install redis
This works for alpine images:
RUN set -xe \
&& apk add --no-cache --update --virtual .phpize-deps $PHPIZE_DEPS \
&& pecl install -o -f redis \
&& echo "extension=redis.so" > /usr/local/etc/php/conf.d/redis.ini \
&& rm -rf /usr/share/php \
&& rm -rf /tmp/* \
&& apk del .phpize-deps
Edit: Added missing backslash
My opinion, the easiest way is:
RUN pecl install redis && docker-php-ext-enable redis
;)
Tried few ways. On alpine php 7.3.5 we can use:
RUN apk add --no-cache pcre-dev $PHPIZE_DEPS \
&& pecl install redis \
&& docker-php-ext-enable redis.so