January 13, 2026Guides
How to Install and Configure Redis on Linux Server
Step-by-step guide on installing Redis caching server on Ubuntu and CentOS for improved application performance.

Redis is an in-memory data structure store used as a database, cache, and message broker. It's essential for high-performance applications requiring fast data access. This guide shows you how to install and configure Redis on your Hiddence server.
Installing Redis on Ubuntu/Debian
bash
sudo apt update
sudo apt install redis-server -y
sudo systemctl start redis-server
sudo systemctl enable redis-server
# Verify installation
redis-cli ping
# Should return: PONGInstalling Redis on CentOS/RHEL
bash
sudo yum install epel-release -y
sudo yum install redis -y
sudo systemctl start redis
sudo systemctl enable redis
# Verify installation
redis-cli ping
# Should return: PONGConfiguring Redis
Edit Redis configuration file to optimize performance:
bash
sudo nano /etc/redis/redis.conf
# Key settings:
# maxmemory 256mb
# maxmemory-policy allkeys-lru
# bind 127.0.0.1 (for security)
# requirepass your_strong_password
sudo systemctl restart redisSecuring Redis
By default, Redis is not password-protected. Set a password:
bash
sudo nano /etc/redis/redis.conf
# Find and uncomment:
requirepass your_strong_password_here
# Restart Redis
sudo systemctl restart redis
# Test connection with password
redis-cli -a your_strong_password_here pingBasic Redis Usage
bash
# Connect to Redis
redis-cli
# Set a key-value pair
SET mykey "Hello Redis"
# Get a value
GET mykey
# Set expiration (TTL)
SETEX mykey 60 "value"
# Check if key exists
EXISTS mykey
# Delete a key
DEL mykeyUsing Redis with PHP
bash
# Install PHP Redis extension
sudo apt install php-redis -y # Ubuntu/Debian
sudo yum install php-redis -y # CentOS
# Restart PHP-FPM
sudo systemctl restart php-fpm
# Test in PHP:
# <?php
# $redis = new Redis();
# $redis->connect('127.0.0.1', 6379);
# $redis->set('test', 'Hello Redis');
# echo $redis->get('test');Redis Best Practices
- Set maxmemory to prevent Redis from using all RAM
- Use appropriate eviction policy (allkeys-lru recommended)
- Enable persistence (RDB or AOF) for data durability
- Monitor Redis memory usage regularly
- Use Redis Sentinel for high availability
- Secure Redis with password and firewall rules
- Backup Redis data regularly