How to install php-redis extension using the official PHP Docker image approach?
To install the php-redis extension using the official PHP Docker image, you can use the docker-php-ext-install script that comes with the image.
The redis extension is available as a PECL package, but the official PHP Docker images provide the docker-php-ext-install command, which automatically fetches and installs PECL extensions like redis.
Here is an example of how you can install the php-redis extension in the official PHP Docker image:
Example of installing php-redis extension using the official PHP Docker image approach
FROM php:7.4-fpm
RUN apt-get update && apt-get install -y libssl-dev zlib1g-dev && docker-php-ext-install redisThis command automatically fetches the extension from PECL, compiles it, and enables it. You do not need to manually run pecl install or install the redis-server daemon, as the PHP extension only requires the client library to communicate with a Redis instance.
Add this to your Dockerfile, build the image, and run a container. The php-redis extension will be available in your PHP environment.
Connecting to Redis from PHP
<?php
$redis = new Redis();
$redis->connect('redis', 6379);
$redis->set('key', 'value');
echo $redis->get('key');
?>