How to Install and Configure Redis on a Dedicated Server

A complete, production-ready walkthrough β€” from zero to a secured, optimized Redis instance on your dedicated server. Covers Ubuntu and CentOS with real commands.

What You'll Learn in This Guide

Redis is one of the most powerful tools you can deploy on a dedicated server. Whether you're running a high-traffic web application, an e-commerce platform, or an API backend, Redis can cut your database load by up to 90% and deliver sub-millisecond response times β€” all by keeping frequently accessed data in RAM.

At Leo Servers, we've helped hundreds of clients set up Redis on dedicated servers. This guide covers everything you need: installation on Ubuntu and CentOS, essential configuration, security hardening, memory tuning, and a quick performance test to confirm it's working.

Install Redis on Ubuntu 22.04 & CentOS 8
Edit redis.conf for production use
Secure Redis with password & firewall rules
Tune memory limits & eviction policies
Enable Redis persistence (RDB & AOF)
Test & benchmark your Redis setup
Set up Redis as a systemd service
Integrate Redis with PHP, Python & WordPress

Table of Contents

What Is Redis and Why Does It Matter for Dedicated Servers?

Redis (Remote Dictionary Server) is an open-source, in-memory data structure store. It functions as a cache, message broker, and NoSQL database simultaneously. Unlike traditional disk-based databases, Redis stores data in RAM, which makes reads and writes orders of magnitude faster.

On a dedicated server, Redis is especially powerful because you have dedicated resources β€” meaning you can allocate a significant portion of RAM to Redis without competing with other tenants. Common use cases include:

  • Session caching β€” store user sessions in Redis instead of the database
  • Object/page caching β€” cache rendered HTML, API responses, and database query results
  • Rate limiting β€” implement efficient request throttling using Redis counters
  • Pub/Sub messaging β€” build real-time features like notifications and live feeds
  • Leaderboards & queues β€” use sorted sets for game leaderboards or task queues
πŸ’‘ Leo Servers Pro Tip

All Leo Servers dedicated server plans include NVMe SSD storage, but Redis bypasses disk entirely β€” it lives in RAM. If your app is database-heavy, pairing it with Redis on a gaming dedicated server or GPU server is one of the highest-ROI infrastructure upgrades you can make.

Prerequisites & System Requirements

Before you install Redis on your dedicated server, make sure you have the following in place:

Requirement Minimum Recommended (Production)
Operating System Ubuntu 20.04 / CentOS 7 Ubuntu 22.04 LTS / CentOS 8+
RAM 512 MB available for Redis 2 GB+ dedicated to Redis
SSH Access Required (root or sudo user) SSH key-based auth recommended
Firewall UFW or firewalld installed Active and configured
Redis Version Redis 6.x Redis 7.x (latest stable)
1

Installing Redis on Ubuntu 22.04

Start by connecting to your dedicated server via SSH. Then follow these steps to install Redis on Ubuntu using the official APT package manager.

Update System Packages

BASH β€” Ubuntu 22.04
# Update the package index
sudo apt update && sudo apt upgrade -y

Install Redis Server

BASH β€” Install Redis
# Install Redis from the official Ubuntu repository
sudo apt install redis-server -y

Enable & Start the Redis Service

BASH β€” systemd
# Enable Redis to start on boot
sudo systemctl enable redis-server

# Start Redis now
sudo systemctl start redis-server

# Verify Redis is running
sudo systemctl status redis-server

Test the Installation

BASH β€” redis-cli
# Connect to the Redis CLI
redis-cli

# Inside redis-cli, type:
127.0.0.1:6379> PING
PONG   # βœ… Redis is running!

# Test basic key-value storage
127.0.0.1:6379> SET leoservers "Hello from Leo Servers"
OK
127.0.0.1:6379> GET leoservers
"Hello from Leo Servers"

127.0.0.1:6379> EXIT
βœ… Success

If you received PONG, Redis is installed and running successfully on your Ubuntu dedicated server.

2

Installing Redis on CentOS / RHEL 8

On CentOS and RHEL-based dedicated servers, the Redis installation process uses the dnf package manager and requires enabling the EPEL repository.

BASH β€” CentOS 8 / RHEL 8
# Enable the EPEL repository
sudo dnf install epel-release -y

# Install Redis
sudo dnf install redis -y

# Enable and start Redis
sudo systemctl enable redis
sudo systemctl start redis

# Verify
sudo systemctl status redis
⚠️ CentOS 7 Note

On CentOS 7, use yum instead of dnf, and the service name is redis (not redis-server). Run: sudo yum install redis -y

3

Configuring Redis for Production

The Redis configuration file is located at /etc/redis/redis.conf (Ubuntu) or /etc/redis.conf (CentOS). Open it with your preferred editor:

BASH
sudo nano /etc/redis/redis.conf
# or on CentOS:
sudo nano /etc/redis.conf

Set the Supervised Mode (Ubuntu Only)

Find the supervised directive and change it from no to systemd:

redis.conf
# Change this:
supervised no

# To this:
supervised systemd

Bind Redis to Localhost

This is a critical security step. By binding Redis to 127.0.0.1, you ensure it only accepts connections from the local server β€” not the open internet.

redis.conf β€” Network Binding
# Bind to localhost only (most secure for single-server setups)
bind 127.0.0.1 -::1

# If Redis needs to accept connections from other servers in your network:
# bind 127.0.0.1 10.0.0.5  (replace with your internal IP)

Set a Password for Redis Authentication

redis.conf β€” Authentication
# Find the requirepass line and set a strong password:
requirepass YourStrongPasswordHere2025!

# Use a long, random string in production β€” at least 32 characters

Configure Memory Limit & Eviction Policy

Telling Redis how much RAM it can use β€” and what to do when that limit is reached β€” is essential for stable operation on a dedicated server.

redis.conf β€” Memory Management
# Set the maximum memory Redis can use (adjust to your server's RAM)
maxmemory 512mb

# Eviction policy: remove least recently used keys when memory is full
# Best for caching use cases:
maxmemory-policy allkeys-lru

# Other common policies:
# volatile-lru  β€” evict keys with expiry, LRU order
# allkeys-lfu   β€” evict least frequently used (Redis 4+)
# noeviction    β€” return error when memory full (use for queues, not caches)

Save Your Changes & Restart Redis

BASH
# Restart Redis to apply config changes
sudo systemctl restart redis-server    # Ubuntu
sudo systemctl restart redis           # CentOS
4

Securing Redis on Your Dedicated Server

An unsecured Redis instance is a serious vulnerability. Redis has been involved in multiple high-profile breaches where attackers exploited exposed Redis ports to write SSH keys and gain root access. Follow these steps to lock it down.

Configure UFW Firewall (Ubuntu)

BASH β€” UFW Firewall
# Block port 6379 from external access (Redis should be local only)
sudo ufw deny 6379

# If you need Redis accessible from a specific trusted IP only:
sudo ufw allow from 10.0.0.5 to any port 6379

# Enable UFW if not already active
sudo ufw enable
sudo ufw status

Configure firewalld (CentOS / RHEL)

BASH β€” firewalld
# Remove Redis port from public zone (block external access)
sudo firewall-cmd --zone=public --remove-port=6379/tcp --permanent

# Reload firewall rules
sudo firewall-cmd --reload

Disable Dangerous Redis Commands

Rename or disable commands like FLUSHALL and CONFIG that could be abused if an attacker gains partial access:

redis.conf β€” Disable Commands
# Disable FLUSHALL (wipes ALL Redis data)
rename-command FLUSHALL ""

# Disable FLUSHDB (wipes a specific DB)
rename-command FLUSHDB ""

# Rename CONFIG to a secret name to prevent unauthorized configuration changes
rename-command CONFIG SECRET_CONFIG_9x3k

# Disable DEBUG command (information leak risk)
rename-command DEBUG ""
⚠️ Important

After renaming CONFIG, update any application code or Redis management tools that use this command to use the new name. Restarting Redis will apply these changes.

5

Enabling Redis Data Persistence

By default, Redis is a cache β€” data is lost when the server restarts. For use cases where durability matters (sessions, queues), enable persistence via RDB snapshots or AOF (Append-Only File) logging.

RDB Snapshots (Default)

redis.conf β€” RDB Persistence
# Save a snapshot every 900 seconds if at least 1 key changed
save 900 1

# Save every 300 seconds if at least 10 keys changed
save 300 10

# Save every 60 seconds if at least 10,000 keys changed
save 60 10000

# Path for the RDB dump file
dir /var/lib/redis
dbfilename dump.rdb

AOF (Append-Only File) β€” More Durable

redis.conf β€” AOF Persistence
# Enable AOF logging
appendonly yes
appendfilename "appendonly.aof"

# Sync policy:
# always   β€” safest, slowest (writes to disk after every command)
# everysec β€” good balance (sync every second, recommended)
# no       β€” OS decides (fastest, least safe)
appendfsync everysec
6

Performance Tuning for Dedicated Servers

On a dedicated server, you have control over OS-level settings that significantly impact Redis performance. These settings prevent Redis from throwing warnings in logs and ensure it operates at full speed.

Disable Transparent Huge Pages (THP)

BASH β€” OS Kernel Settings
# Disable THP (Redis recommends this; THP causes latency spikes)
echo never > /sys/kernel/mm/transparent_hugepage/enabled

# Make it permanent across reboots by adding to /etc/rc.local:
echo 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' >> /etc/rc.local

Set vm.overcommit_memory

BASH β€” Kernel Parameter
# Allow Redis to use more memory during background saves (fork)
sudo sysctl vm.overcommit_memory=1

# Make permanent:
echo "vm.overcommit_memory = 1" | sudo tee -a /etc/sysctl.conf
sudo sysctl -p

Increase File Descriptor Limits

redis.conf
# Allow Redis to handle more simultaneous connections
maxclients 10000

# Increase the backlog for TCP connections
tcp-backlog 511
7

Integrating Redis with Your Application

PHP Integration (phpredis extension)

BASH β€” PHP Redis
# Install the PHP Redis extension
sudo apt install php-redis -y   # Ubuntu
sudo dnf install php-pecl-redis -y  # CentOS

# Restart PHP-FPM
sudo systemctl restart php8.1-fpm

Python Integration (redis-py)

Python β€” redis-py
# Install redis-py
pip install redis

# Python code:
import redis

r = redis.Redis(
    host='127.0.0.1',
    port=6379,
    password='YourStrongPasswordHere2025!',
    decode_responses=True
)

# Store a value with 60-second TTL
r.setex('session:user42', 60, 'active')

# Retrieve
status = r.get('session:user42')
print(status)  # Output: active

WordPress Object Cache (WP Redis Plugin)

To use Redis as an object cache in WordPress on your dedicated server, install the Redis Object Cache plugin, then add this to wp-config.php:

wp-config.php
// Redis connection settings for WordPress
define( 'WP_REDIS_HOST', '127.0.0.1' );
define( 'WP_REDIS_PORT', 6379 );
define( 'WP_REDIS_PASSWORD', 'YourStrongPasswordHere2025!' );
define( 'WP_REDIS_DATABASE', 0 );
define( 'WP_REDIS_TIMEOUT', 1 );
define( 'WP_REDIS_READ_TIMEOUT', 1 );

Frequently Asked Questions & Troubleshooting

Troubleshooting

  • Redis Not Starting? Check logs via sudo journalctl -u redis-server -n 50 --no-pager
  • Connection Refused? Confirm Redis is running and the bind directive in redis.conf is configured correctly. Ensure the firewall isn't blocking internal access.
  • High Memory Usage? Check memory with redis-cli INFO memory | grep used_memory_human and ensure a maxmemory limit is set.

FAQ

What is the default port for Redis on a dedicated server?
Redis listens on port 6379 by default. For security, you should either change this port using the port directive in redis.conf or block it from external access using your server's firewall (UFW or firewalld).
Can I run Redis and MySQL on the same dedicated server?
Yes β€” and this is actually the most common setup. Redis acts as a caching layer in front of MySQL, so frequently queried data is served from Redis (RAM) instead of hitting MySQL (disk). The two services work very well together and this combination can reduce your database load by 60–90%.
How much RAM should I allocate to Redis?
As a general rule, allocate 20–30% of your total dedicated server RAM to Redis for caching. On a 32 GB RAM server, 6–8 GB for Redis is a reasonable starting point. Always set the maxmemory directive to prevent Redis from consuming all available memory.

Need a Dedicated Server Ready for Redis?

Leo Servers offers high-performance dedicated servers with NVMe SSDs and DDR4 RAM β€” perfect for Redis deployments that demand speed and reliability.

View Dedicated Server Plans β†’

Conclusion

You've successfully learned how to install and configure Redis on a dedicated server β€” from initial installation on Ubuntu and CentOS, through essential redis.conf settings, security hardening with firewall rules and password authentication, enabling data persistence, and integrating Redis with PHP, Python, and WordPress.

Redis is one of the most impactful performance upgrades you can make on a dedicated server. When properly configured, it can handle hundreds of thousands of requests per second from RAM β€” transforming slow, database-heavy applications into lightning-fast experiences.

At Leo Servers, our dedicated server infrastructure is purpose-built for workloads like Redis. If you have questions about your Redis configuration or want expert guidance on server setup, our team is ready to help.

Discover Leo Servers Dedicated Server Locations

Leo Servers servers are available around the world, providing diverse options for hosting high-performance environments. Each region offers unique advantages, making it easier to choose a location that best suits your specific hosting needs.