// Blog

How to Install and Configure Redis on a Linux VPS: Complete Guide for Caching and Sessions — CLIQHOST

October 30, 2026 · by Alex M.

How to Install and Configure Redis on a Linux VPS: Complete Guide for Caching and Sessions — CLIQHOST

The performance of a modern web application largely depends on how fast the server responds to repeated requests. Relational databases are excellent for storing data, but querying them on every HTTP request costs time and resources. Redis solves exactly this problem: an in-memory data store, blazing fast, widely used for caching, session management, and message queues.

In this complete guide, you'll learn how to install, configure, and secure Redis on a Linux VPS from CLIQHOST step by step, with concrete command examples and configuration settings.


What Is Redis and Why Should You Use It?

Redis (Remote Dictionary Server) is an open-source key-value data store that runs entirely in RAM. This makes it hundreds of times faster than a traditional database for read/write operations.

Common Use Cases

  • Object caching for WordPress / Joomla / Drupal — eliminates repetitive SQL queries
  • PHP session storage — faster and more scalable sessions
  • Rate limiting — control the number of requests per IP
  • Message queues — publish/subscribe for Node.js, Python and more
  • Leaderboards and counters — atomic real-time data structures

If you run a medium-to-high-traffic site on a CLIQHOST NVMe VPS, adding Redis can dramatically reduce your application's response time.


Prerequisites

Before you begin, make sure you have:

  • A VPS running Ubuntu 22.04 / 24.04 or Debian 12
  • Root access or a user with sudo privileges
  • An up-to-date system

If you don't have a server yet, you can quickly order a VPS SSD or VPS NVMe from cliqhost.com.


Step 1: Update the System

Always start by updating the package list:

sudo apt update && sudo apt upgrade -y

Step 2: Install Redis

Redis is available in the official Ubuntu/Debian repositories:

sudo apt install redis-server -y

Check the installed version:

redis-server --version

Expected output:

Redis server v=7.0.15 sha=00000000:0 malloc=jemalloc-5.3.0 bits=64

Check the service status:

sudo systemctl status redis-server

If the service isn't running:

sudo systemctl start redis-server
sudo systemctl enable redis-server

Step 3: Configure Redis (redis.conf)

The main configuration file is located at /etc/redis/redis.conf:

sudo nano /etc/redis/redis.conf

3.1 Supervised Mode

Since Ubuntu/Debian use systemd, find the line:

supervised no

And change it to:

supervised systemd

3.2 Memory Limit

Without a limit, Redis can consume all available RAM. Add or modify:

maxmemory 256mb
maxmemory-policy allkeys-lru

Eviction policies explained (maxmemory-policy):

Policy Behavior
allkeys-lru Evicts least recently used keys (recommended for cache)
volatile-lru Evicts only keys with a TTL set
noeviction Returns an error when memory is full (for critical data)
allkeys-random Evicts random keys

3.3 Enabling Persistence (Optional)

By default, Redis saves data to disk periodically (RDB snapshots). If you use Redis exclusively for caching, disable persistence for maximum performance:

save ""

For session storage, keep the defaults or enable AOF:

appendonly yes
appendfilename "appendonly.aof"

3.4 Bind Address and Network Security

By default, Redis listens only on localhost (127.0.0.1) — this is the correct, secure behavior:

bind 127.0.0.1 -::1

Never expose Redis on a public IP without authentication and a firewall!

After making changes, restart Redis:

sudo systemctl restart redis-server

Step 4: Secure Redis with a Password

Even though Redis only listens on localhost by default, setting a password adds an extra security layer:

sudo nano /etc/redis/redis.conf

Find the line:

# requirepass foobared

Uncomment it and set a strong password:

requirepass Str0ng#Password2025!

Restart the service:

sudo systemctl restart redis-server

Test authentication:

redis-cli
127.0.0.1:6379> AUTH Str0ng#Password2025!
OK
127.0.0.1:6379> PING
PONG

If you need comprehensive server hardening, the CLIQHOST server management team can handle the full security setup for you.


Step 5: Testing Redis with redis-cli

redis-cli is the built-in command-line client. Common operations:

redis-cli -a Str0ng#Password2025!

Set and retrieve values:

SET website "cliqhost.com"
GET website
# Output: "cliqhost.com"

Set a value with expiration (TTL in seconds):

SETEX cache_homepage 3600 "<html>...</html>"
TTL cache_homepage
# Output: 3599

Server statistics:

INFO server
INFO memory
INFO stats

Total number of keys:

DBSIZE

Step 6: Integrating Redis with PHP (Sessions and Object Cache)

6.1 Installing the PHP Redis Extension

sudo apt install php-redis -y

Verify the installation:

php -m | grep redis
# Output: redis

6.2 Configuring PHP Sessions with Redis

Open the PHP configuration file (adjust the version number):

sudo nano /etc/php/8.2/fpm/php.ini

Modify or add:

session.save_handler = redis
session.save_path = "tcp://127.0.0.1:6379?auth=Str0ng#Password2025!"

Restart PHP-FPM:

sudo systemctl restart php8.2-fpm

User sessions are now stored in Redis instead of disk — faster and easier to scale.

6.3 WordPress Object Cache with Redis

For WordPress hosted on a CLIQHOST VPS or WordPress hosting plan, install the Redis Object Cache plugin:

  1. Go to WordPress Admin → Plugins → Add New → search for "Redis Object Cache"
  2. Add to wp-config.php:
define('WP_REDIS_HOST', '127.0.0.1');
define('WP_REDIS_PORT', 6379);
define('WP_REDIS_PASSWORD', 'Str0ng#Password2025!');
define('WP_REDIS_DATABASE', 0);
  1. Activate via Settings → Redis Object Cache → Enable Object Cache

You'll immediately see reduced response times for dynamic pages.


Step 7: Monitoring Redis

Real-Time Monitoring

redis-cli -a Str0ng#Password2025! monitor

This displays all commands processed in real time — useful for debugging, but resource-intensive in production.

Memory Statistics

redis-cli -a Str0ng#Password2025! INFO memory | grep -E 'used_memory_human|maxmemory_human|mem_fragmentation_ratio'

Sample output:

used_memory_human:12.50M
maxmemory_human:256.00M
mem_fragmentation_ratio:1.15

Latency Check

redis-cli -a Str0ng#Password2025! --latency

Slow Log

Enable slow command logging in redis.conf:

slowlog-log-slower-than 10000
slowlog-max-len 128

View slow commands:

redis-cli SLOWLOG GET 10

Step 8: Firewall Configuration for Redis

If UFW is active on your server, make sure port 6379 is not open to the public:

sudo ufw status

Port 6379 should not appear in the list of allowed rules for external sources. If Redis needs to be reached from a separate server (e.g., in a cluster), allow access only from a specific IP:

sudo ufw allow from 10.0.0.5 to any port 6379

Replace 10.0.0.5 with the private IP of your application server.

For high-traffic projects, a CLIQHOST dedicated server provides the RAM and throughput Redis needs to operate at full capacity.


Step 9: Advanced Optimizations

9.1 Disable Transparent Huge Pages

Redis recommends disabling THP to reduce latency:

echo never | sudo tee /sys/kernel/mm/transparent_hugepage/enabled

To persist across reboots, add to /etc/rc.local:

echo never > /sys/kernel/mm/transparent_hugepage/enabled

9.2 Set vm.overcommit_memory

sudo sysctl vm.overcommit_memory=1
echo 'vm.overcommit_memory = 1' | sudo tee -a /etc/sysctl.conf

This prevents "fork failed" errors when creating RDB snapshots.

9.3 Increase Connection Limit (somaxconn)

sudo sysctl -w net.core.somaxconn=65535
echo 'net.core.somaxconn = 65535' | sudo tee -a /etc/sysctl.conf

Redis by Hosting Type

Hosting Type Redis Recommended? Notes
Shared Hosting cPanel ❌ / Limited Depends on provider; check availability on CLIQHOST cPanel hosting
VPS SSD / NVMe ✅ Absolutely Full control, dedicated resources
Dedicated Server ✅ Ideal Abundant RAM, minimal latency
Application Cluster ✅ Redis Cluster Multiple nodes, automatic replication

For production apps with high traffic, a managed dedicated server from CLIQHOST provides all the resources Redis needs to shine.


Quick Reference: Essential Commands

# Install
sudo apt install redis-server -y

# Status
sudo systemctl status redis-server

# Restart
sudo systemctl restart redis-server

# Test connection
redis-cli -a PASSWORD ping

# Full info
redis-cli -a PASSWORD INFO

# Flush current database cache (careful in production!)
redis-cli -a PASSWORD FLUSHDB

# Flush all databases
redis-cli -a PASSWORD FLUSHALL

Conclusion

Redis is one of the most valuable tools you can add to a Linux server to boost web application performance. Through intelligent caching, PHP session management, and reduced database load, Redis dramatically transforms response times for dynamic sites.

If you need a server to deploy Redis without the hassle, choose a CLIQHOST NVMe VPS — dedicated resources, ultra-fast NVMe storage, and responsive technical support. Or contact us to get a personalized recommendation based on your project's needs.

SHARE
// what clients say

What Our Clients Say

Real reviews from customers who trust CLIQHOST for performance, reliability and expert technical support.

★★★★★

"We moved our online shop from a foreign host and the difference is night and day — pages load instantly and support replies in minutes, in Romanian."

AM
Andrei M.
eCommerce owner · Chișinău
★★★★★

"Migrated 12 client sites to CLIQHOST. Free migration, zero downtime, and the cPanel setup is exactly what my team needed. Highly recommend."

EV
Elena V.
Web agency · Bălți
★★★★★

"Our NVMe VPS handles traffic spikes without a sweat. Full root, local datacenter, and billing in MDL — everything we wanted from a provider."

DC
Dmitri C.
SaaS founder · Chișinău