Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 say that I can install extensions this way, installing dependencies for extensions manually:

FROM php:5.6-fpm # Install modules (iconv, mcrypt and gd extensions) RUN apt-get update && apt-get install -y \         libfreetype6-dev \         libjpeg62-turbo-dev \         libmcrypt-dev \         libpng12-dev \     && docker-php-ext-install iconv mcrypt \     && docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \     && docker-php-ext-install gd CMD ["php-fpm"] 

Without Docker I installed it with apt-get install php5-redis. But how can I install it using the approach above?

like image 485
starikovs Avatar asked Jul 12 '15 16:07

starikovs


People also ask

What is Docker PHP ext install?

docker-php-ext-enableThis command is used to start PHP extension of When we use pecl to install the PHP extension, the extension is not started by default. If you want to use this extension, you must configure it in the php. ini configuration file to use this PHP extension.

Does Docker have PHP?

PHP Core ExtensionsIf an extension needs custom configure arguments, you can use the docker-php-ext-configure script like this example. There is no need to run docker-php-source manually in this case, since that is handled by the configure and install scripts.


1 Answers

Redis is not an extension that is included in “php-src”, therefore you cannot use docker-php-ext-install. Use PECL:

RUN pecl install -o -f redis \ &&  rm -rf /tmp/pear \ &&  docker-php-ext-enable redis 

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 
like image 111
TimWolla Avatar answered Sep 22 '22 18:09

TimWolla