Php7 Redis client on Alpine OS

I created a docker image using alpine 3.5 as my base image. I want my php application running inside a container to communicate with the redis server. But I don't find php7-redis client in Alpine.

Is there a work environment? I tried to use pecl to install redis, but there is no pecl package in alpine. I tried with pear but pear doesn't have redis package. Any thoughts on this?

+3


source to share


3 answers


You can find your solution here https://pkgs.alpinelinux.org/package/edge/community/x86_64/php7-redis



+2


source


php7-redis is in v3.6 (released yesterday) and edge (roll / unstable) as you can easily find pkgs.alpinelinux.org .



pecl is currently provided by the php7-pear package.

+2


source


For Alpine versions prior to 3.6, such as the current official PHP Alpine image (Alpine 3.4), you need to build the extension from source. You need to make a few dependencies: autoconf

, git

, gcc/g++

and make

. As an example, this is the complete Dockerfile for the latest stable version of PHP built on Alpine with the php7 redis extension installed and enabled:

FROM php:alpine

RUN apk add --no-cache autoconf git g++ make

RUN \
  git clone https://github.com/phpredis/phpredis.git && \
  cd phpredis && \
  git checkout php7 && \
  phpize && \
  ./configure && \
  make && make install && \
  docker-php-ext-enable redis

      

If you want a smaller image, you can delete the phpredis directory and folders that were needed for cloning and building afterwards. If you are not using the official PHP image, you need to replace docker-php-ext-enable redis

with a couple of commands to move redis.so

where you need it and add a line extension=redis.so

to your PHP config.

+2


source







All Articles