Redis Configuration
Redis (Remote Dictionary Server) is an open-source, in-memory data structure store used primarily as a fast database, cache, and message broker.
To install the latest version of Redis & to configure it, please follow the steps mentioned below:
Single-Server Redis & PHP 8.5 Setup
This guide provides a comprehensive walkthrough for installing and configuring Redis Server and the PHP 8.5 Redis client extension on the same instance. This co-located architecture minimizes network latency, making it an excellent topology for high-performance caching and fast session management.
Topology Overview
When hosting the application layer and caching layer on a single server, communication occurs entirely over the local loopback interface (127.0.0.1 or localhost).
- Nginx handles incoming traffic and forwards requests to the local PHP-FPM Unix socket.
- PHP 8.5-FPM executes code and invokes the native compiled extension (
php8.5-redis). - Redis Server listens locally on port
6379, receiving data requests straight from the PHP extension via internal TCP frames.
Step 1: Install and Configure Redis Server
Update the local repository listings and install the standalone Redis database engine.
sudo apt update
sudo apt install redis-server -y
Initializing the Systemd Supervisor
Out of the box, Redis does not explicitly tie into Ubuntu's init system daemon. To ensure it handles system shutdowns, restarts, and boot processes cleanly, update its supervision strategy.
- Open the primary configuration file:
sudo nano /etc/redis/redis.conf
- Search for the
superviseddirective (Ctrl + Win nano) and change its value fromnotosystemd:
# Before: supervised no
supervised systemd
- Save the changes and exit.
- Restart the database service to apply the configuration change:
sudo systemctl restart redis-server
Ensure Redis is running actively and without errors by checking its service status:
sudo systemctl status redis-server
Step 2: Install the PHP 8.5 Client Extension
Since the PHP application needs to communicate with the database engine, install the native client extension. This builds the bridge so PHP can translate code commands into Redis protocols.
sudo apt install php8.5-redis -y
Activating the Module within PHP-FPM
For the web server's PHP processing layer to load the new binary, restart the php8.5-fpm background daemon:
sudo systemctl restart php8.5-fpm
Verify that the runtime environment successfully registers and exposes the client modules by running a quick CLI test:
php -m | grep redis
If the shell outputs redis, the module layer is ready to accept database commands.
Step 3: Verification Application Script
To verify that the Web server, the PHP 8.5 engine, the local client driver, and the Redis server are interacting seamlessly, run the test script.
Run the file named redis-test.php within the tests directory:
sudo nano /var/www/tests/redis-test.php
Component Reference
If both pieces (Server & Client) live on the same instance, keep their distinct roles clear during updates or debugging:
| Service Boundary | Active System Element | Primary Log File Path |
|---|---|---|
| The Server (Database Engine) | Managed via redis-server.service | /var/log/redis/redis-server.log |
| The Client (PHP Extension) | Embedded within php8.5-fpm.service | /var/log/php8.5-fpm.log |
Summary Table
| Feature | php8.5-redis | php8.5-redis-server |
|---|---|---|
| Role | PHP Driver / Client | Database Engine / Server |
| What it installs | redis.so (PHP extension module) | redis-server (System service) |
| Runs as | Part of the PHP / PHP-FPM process | A background system daemon (systemd) |
| Code Usage | Allows to write $redis->set() in PHP | Does not read PHP; just processes incoming raw TCP data |
Need both?
- Yes, if everything is on one machine: If the PHP app and the Redis database live on the same instance, install both so PHP can talk to the database running locally.
- No, if Redis is hosted elsewhere: If connecting to an external Redis server (like AWS ElastiCache or a separate database server), only install
php8.5-redison the instance.