For our Blog Visitor only Get Additional 3 Month Free + 10% OFF on TriAnnual Plan YSBLOG10
Grab the Deal

How to Install Redis on Linux Server: (Step-by-Step Guide 2026)

To install Redis on a Linux server, update your system, install Redis via the package manager (apt or dnf/yum), enable and start the service, then secure and tune it. On Ubuntu: apt install redis-server; on RHEL-based: dnf install redis. Configure /etc/redis/redis.conf for bind, auth, persistence, and performance, then verify with redis-cli.

Installing Redis on a Linux Server is one of the quickest ways to speed up databases and applications. In this step-by-step guide, you’ll learn how to install, secure, configure, and tune Redis on Ubuntu/Debian and CentOS/RHEL/Rocky/AlmaLinux, plus how to use it for WordPress object caching. I’ll also share real-world production tips from years of managing high-traffic environments.

What is Redis and Why Install it on a Linux Server?

What Is Redis and Why Install It on a Linux Server?

Redis is an in-memory data store used as a cache, database, and message broker. It’s blazing fast and perfect for reducing database load, storing sessions, queues, rate limiting, and real-time analytics. On Linux, it’s lightweight, secure, and easy to automate with systemd.

Top Use Cases

Prerequisites

  • A Linux server (Ubuntu/Debian or CentOS/RHEL/Rocky/AlmaLinux).
  • Root or sudo access.
  • Open local access or firewall rules for port 6379 (only if needed externally).
  • Basic command-line comfort.

Quick Install: Redis on Ubuntu/Debian

Install via APT

sudo apt update
sudo apt install -y redis-server

Enable systemd Supervision and Secure Defaults

Set Redis to be managed by systemd and listen only on localhost by default. On Ubuntu, the package typically enables protected-mode and binds to 127.0.0.1. Confirm and adjust:

sudo nano /etc/redis/redis.conf
# Ensure:
supervised systemd
bind 127.0.0.1 ::1
protected-mode yes
port 6379

Start, Enable, and Verify

sudo systemctl enable redis-server
sudo systemctl restart redis-server
sudo systemctl status redis-server --no-pager
redis-cli ping
# Expected: PONG

Install Redis on CentOS/RHEL/Rocky/AlmaLinux

Install via DNF/YUM

On modern RHEL derivatives, Redis is available via the default or EPEL repositories. If Redis isn’t found, enable EPEL first.

# Optional if Redis not found:
sudo dnf install -y epel-release

# Install Redis
sudo dnf install -y redis  # or: sudo yum install -y redis

# Configure basic settings
sudo nano /etc/redis/redis.conf
# Ensure:
supervised systemd
bind 127.0.0.1 ::1
protected-mode yes
port 6379

Start, Enable, and Verify

sudo systemctl enable redis
sudo systemctl restart redis
sudo systemctl status redis --no-pager
redis-cli ping

Install the Latest Redis from Source (Any Linux)

If you need the newest Redis features or performance fixes before your distro packages them, build from source. This installs Redis under /usr/local and creates a systemd service.

# Install build tools
# Debian/Ubuntu:
sudo apt update && sudo apt install -y build-essential tcl pkg-config
# RHEL/Rocky/Alma/CentOS:
sudo dnf groupinstall -y "Development Tools"
sudo dnf install -y tcl pkgconfig

# Download and build Redis (replace version as needed)
curl -O https://download.redis.io/redis-stable.tar.gz
tar xzf redis-stable.tar.gz
cd redis-stable
make -j$(nproc)
sudo make install

# Create user, directories, and config
sudo useradd -r -s /bin/false redis || true
sudo mkdir -p /etc/redis /var/lib/redis /var/log/redis /var/run/redis
sudo chown -R redis:redis /var/lib/redis /var/log/redis /var/run/redis

# Copy example config
sudo cp redis.conf /etc/redis/redis.conf
sudo sed -i 's/^supervised no/supervised systemd/' /etc/redis/redis.conf
sudo sed -i 's|^dir .*|dir /var/lib/redis|' /etc/redis/redis.conf
sudo sed -i 's/^bind .*/bind 127.0.0.1 ::1/' /etc/redis/redis.conf
sudo sed -i 's/^protected-mode no/protected-mode yes/' /etc/redis/redis.conf

# Create systemd service
sudo tee /etc/systemd/system/redis.service > /dev/null <<'EOF'
[Unit]
Description=Redis In-Memory Data Store
After=network.target

[Service]
User=redis
Group=redis
ExecStart=/usr/local/bin/redis-server /etc/redis/redis.conf
ExecStop=/usr/local/bin/redis-cli shutdown
Restart=always
LimitNOFILE=10032

[Install]
WantedBy=multi-user.target
EOF

sudo systemctl daemon-reload
sudo systemctl enable --now redis
redis-cli ping

Secure Redis Configuration (Must-Do)

Bind to Localhost or Private Network

Never expose Redis directly to the public internet. Keep it on 127.0.0.1 or a private VLAN. If you must expose it, enforce TLS, strong authentication, and firewall rules.

# /etc/redis/redis.conf
bind 127.0.0.1 ::1
protected-mode yes
port 6379
# Optional: Unix socket (fast and secure on single host)
unixsocket /var/run/redis/redis.sock
unixsocketperm 770

Add Authentication and ACLs

Set a strong password and consider ACLs (Redis 6+). Avoid sharing the default user for multi-app environments.

# /etc/redis/redis.conf
requirepass <STRONG_LONG_PASSWORD>  # or use ACLs below

# ACL example: Create a limited user for an app
# Run in redis-cli as an admin user:
ACL SETUSER appuser on >>pass=<APP_PASSWORD> +@read +@write ~*
# Verify:
ACL LIST

Firewall: Allow Only What You Need

# UFW (Ubuntu)
sudo ufw allow from 127.0.0.1 to any port 6379 proto tcp
# Or allow from your app server's private IP only:
sudo ufw allow from 10.0.0.10 to any port 6379 proto tcp

# firewalld (RHEL)
sudo firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="10.0.0.10" port protocol="tcp" port="6379" accept'
sudo firewall-cmd --reload

(Optional) Enable TLS for Remote Connections

For cross-server traffic, enable TLS. Generate certificates, then configure:

# /etc/redis/redis.conf
tls-port 6379
port 0
tls-cert-file /etc/ssl/redis.crt
tls-key-file /etc/ssl/redis.key
tls-ca-cert-file /etc/ssl/ca.crt

Persistence and Data Durability

Redis offers RDB snapshots and AOF (Append Only File). For caching-only use, you can disable persistence. For queues or critical state, enable both with sane policies.

# /etc/redis/redis.conf

# RDB snapshots (default examples)
save 900 1
save 300 10
save 60 10000
dbfilename dump.rdb
dir /var/lib/redis

# AOF: safer durability
appendonly yes
appendfsync everysec
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb

If Redis is purely a cache, consider disabling persistence to avoid disk churn:

# For caching-only
save ""
appendonly no

Performance Tuning for Production

Set Memory Limits and Eviction Policy

Define how much RAM Redis can use and what to evict when full. LRU policies are common for caches.

# /etc/redis/redis.conf
maxmemory 4gb
maxmemory-policy allkeys-lru   # Alternatives: volatile-lru, allkeys-random, noeviction, etc.

Kernel and System Tweaks

These settings reduce latency spikes and memory allocation issues.

# sysctl
echo "vm.overcommit_memory=1" | sudo tee -a /etc/sysctl.conf
echo "net.core.somaxconn=1024" | sudo tee -a /etc/sysctl.conf
sudo sysctl -p

# Transparent Huge Pages off (best-effort; may vary by distro)
echo never | sudo tee /sys/kernel/mm/transparent_hugepage/enabled
echo never | sudo tee /sys/kernel/mm/transparent_hugepage/defrag

# Persist THP change across reboots (systemd drop-in)
sudo tee /etc/systemd/system/disable-thp.service > /dev/null <<'EOF'
[Unit]
Description=Disable Transparent Huge Pages
After=network.target

[Service]
Type=oneshot
ExecStart=/bin/sh -c 'echo never > /sys/kernel/mm/transparent_hugepage/enabled'
ExecStart=/bin/sh -c 'echo never > /sys/kernel/mm/transparent_hugepage/defrag'

[Install]
WantedBy=multi-user.target
EOF

sudo systemctl daemon-reload
sudo systemctl enable --now disable-thp

# Raise open file limits for the redis user
echo -e "redis soft nofile 10032\nredis hard nofile 10032" | sudo tee /etc/security/limits.d/redis.conf

Also ensure supervised systemd is set, and consider a dedicated SSD for persistence files to reduce latency.

Monitoring and Maintenance

Health Checks and Metrics

# Quick health and stats
redis-cli ping
redis-cli info memory
redis-cli info stats
redis-cli slowlog get 10

Track key metrics: used_memory, evicted_keys, connected_clients, instantaneous_ops_per_sec, and latency spikes. For deeper observability, integrate Redis Exporter with Prometheus/Grafana.

Logging and Backups

Configure loglevel (notice or warning) and ensure logs rotate. Back up RDB and AOF files regularly if you store critical data.

# /etc/redis/redis.conf
loglevel notice
logfile /var/log/redis/redis.log

Use Redis for WordPress Object Caching

Connecting WordPress to Redis dramatically reduces database queries and boosts TTFB. Use a persistent object caching plugin and confirm connections.

Steps on Ubuntu/Debian with PHP-FPM

# Install PHP Redis extension
sudo apt install -y php-redis
sudo systemctl restart php-fpm || sudo systemctl restart php8.2-fpm

# Install a Redis object cache plugin (e.g., via wp-cli)
wp plugin install redis-cache --activate
wp redis enable
wp redis status

Set the WordPress plugin to use 127.0.0.1:6379 or a Unix socket for best performance. If you set requirepass or ACLs, configure the plugin accordingly.

At YouStable, our Managed VPS and Dedicated Servers come Redis-ready, with optimized PHP-FPM and NGINX/Apache stacks. If you prefer not to manage config and tuning yourself, we’ll deploy and harden Redis for you.

Common Errors and Fixes

“Could not connect to Redis”

  • Service down: systemctl status redis or redis-server.
  • Firewall blocking: open only to required hosts.
  • Wrong host/port/socket: verify plugin/app configuration.
  • Auth required: set correct password or ACL user and permissions.

Redis Not Starting

  • Config syntax error: check /var/log/redis/redis.log.
  • Bad directory permissions: ensure Redis owns /var/lib/redis and /var/run/redis.
  • Port conflict: confirm nothing else uses 6379.
  • Systemd not supervising: set supervised systemd in redis.conf.

High Evictions or OOM

  • Increase RAM or lower data size.
  • Set maxmemory with an appropriate eviction policy.
  • Review key TTLs and data structures.
  • Disable persistence for cache-only use cases.

Verification and Basic Benchmark

Confirm functionality and run a lightweight benchmark to validate throughput. Don’t benchmark on production without care.

# Quick set/get
redis-cli set test "ok"
redis-cli get test

# Basic benchmark (local)
redis-benchmark -q -n 10000 -c 50 -t set,get

Best Practices Checklist

  • Keep Redis private; never open to the internet without TLS and strict ACLs.
  • Set requirepass or ACLs; rotate secrets periodically.
  • Use supervised systemd and enable service on boot.
  • Define maxmemory and an eviction policy suitable for your workload.
  • Enable AOF if you need stronger durability; disable persistence for cache-only.
  • Apply kernel tweaks: overcommit_memory=1, THP=never, somaxconn=1024.
  • Monitor memory, latency, slowlog, and evictions; alert on anomalies.
  • Back up RDB/AOF if data is critical; test restores.

FAQs: Install Redis on Linux Server

Is Redis free to use on Linux servers?

Yes. Redis is open-source (BSD license) and free to use on Linux. You can install it via your package manager or build from source without cost.

Should I use APT/DNF packages or build Redis from source?

For most users, distro packages are stable and well-integrated. Build from source when you need the latest features or performance fixes not yet packaged by your OS.

How do I secure Redis if I must expose it to another server?

Bind to a private IP, enforce a firewall allowlist, require strong auth or ACLs, and enable TLS. Alternatively, use an SSH tunnel or a private VPC peering connection.

What Redis persistence mode should I use?

For cache-only, disable persistence. For queues and critical state, enable AOF (everysec) and keep periodic RDB snapshots for faster restarts. Always test recovery.

How much RAM should I allocate to Redis?

Set maxmemory so Redis uses 60–80% of available RAM, leaving headroom for the OS and other services. Adjust based on dataset size, overhead, and expected growth.

Does Redis help WordPress performance?

Yes. Object caching via Redis can significantly reduce database queries and improve backend responsiveness, especially on dynamic or high-traffic sites. Pair it with full-page caching for best results.

Can YouStable install and manage Redis for me?

Absolutely. YouStable’s Managed VPS and Dedicated Servers include Redis installation, hardening, performance tuning, and ongoing monitoring—so you can focus on your applications.

With these steps, you can confidently install Redis on a Linux server, secure it to production standards, and extract real performance gains for databases, APIs, and WordPress sites. Keep it private, monitor continuously, and fine-tune memory and persistence for your workload.

Prahlad Prajapati

Prahlad is a web hosting specialist and SEO-focused organic growth expert from India. Active in the digital space since 2019, he helps people grow their websites through clean, sustainable strategies. Passionate about learning and adapting fast, he believes small details create big success. Discover his insights on web hosting and SEO to elevate your online presence.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top