Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Php7 Redis Client on Alpine OS

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

Is there a workway around it ?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 issue ?

like image 796
SmrutiRanjan Avatar asked Jan 03 '23 23:01

SmrutiRanjan


1 Answers

For versions of Alpine prior to 3.6, such as the current official PHP Alpine image (Alpine 3.4), you need to build the extension from source. There are a few dependencies you also need to do that: autoconf, git, gcc/g++, and make. As an example, this is a complete Dockerfile for the latest stable release of PHP built on Alpine with the redis extension for php7 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 remove the phpredis directory and the deps that were needed to clone and build it afterward. If you're not using an official PHP image then you will need to replace docker-php-ext-enable redis with a couple of commands to move the redis.so where you need it and add the extension=redis.so line to your PHP config.

like image 95
Paul Avatar answered Jan 08 '23 07:01

Paul