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

How to Create Redis on Linux Server in 2026? – (Full Complete Guide)

To create Redis on a Linux server, install the Redis package, enable and start its systemd service, secure the default configuration, and verify with redis-cli. Use apt on Ubuntu/Debian or dnf/yum on RHEL/AlmaLinux.

Then configure networking, authentication, and persistence, and test performance with redis-benchmark. In this guide, you’ll learn exactly how to create Redis on Linux server the right way—installing, configuring, securing, and tuning it for production.

Whether you’re accelerating WordPress, offloading sessions, or running queues, this step-by-step tutorial uses beginner-friendly language while following the best practices we implement daily on real servers.

What is Redis and Why Run it on Linux?

Redis is an in-memory data store used as a cache, database, and message broker. It excels at ultra-low-latency reads/writes and supports data structures like strings, lists, sets, hashes, and streams.

On a Linux server, Redis speeds up applications—especially WordPress, Laravel, and microservices—by offloading repeated queries and enabling fast session and queue handling.

Prerequisites and System Requirements

  • Root or sudo access to a Linux server (Ubuntu/Debian or RHEL/CentOS/AlmaLinux/Rocky)
  • 1–2 GB RAM minimum for testing; 4 GB+ recommended for production caching
  • Open TCP port 6379 (limit exposure to trusted IPs only)
  • Shell access via SSH and a basic text editor (nano or vim)

Ubuntu/Debian

Ubuntu and Debian maintain a stable Redis package in their repositories. This is the quickest path for most setups.

sudo apt update
sudo apt install -y redis-server

# Verify service
systemctl status redis-server --no-pager

# Enable on boot
sudo systemctl enable redis-server

Default configuration file: /etc/redis/redis.conf. Data directory: /var/lib/redis. Service name: redis-server.

RHEL/CentOS/AlmaLinux/Rocky

On RHEL-based systems, Redis is available via AppStream/EPEL. Newer versions often come from EPEL or the Remi repository.

# Enable EPEL (where applicable)
sudo dnf install -y epel-release
# Install Redis
sudo dnf install -y redis

# Start and enable
sudo systemctl enable --now redis

# Check status
systemctl status redis --no-pager

Default configuration file: /etc/redis/redis.conf. Data directory: /var/lib/redis. Service name: redis.

Verify the Installation

# Check Redis version
redis-cli --version

# Test connectivity and basic operations
redis-cli ping
redis-cli set youstable "fast-cache"
redis-cli get youstable

If you receive PONG and the set/get works, Redis is running correctly.

Secure and Configure redis.conf

By default, Redis is safe for localhost use. For production or remote access, harden it. Edit the config file, then restart the service.

Core Settings

# /etc/redis/redis.conf

# Bind to localhost (add your private IP if needed)
bind 127.0.0.1 ::1

# Keep protected mode on
protected-mode yes

# Use systemd supervision for clean service management
supervised systemd

# Keep default port (change if needed)
port 6379

If you must allow remote access, add a specific private IP to bind and restrict via firewall to trusted sources only.

Enable Authentication

Redis 6+ supports ACLs. For simplicity, set a strong password (this sets the default user’s password). For more granular control, use ACL rules.

# Minimal password protection
requirepass Your_Very_Strong_#Redis_Password_2025

# Optional: ACL example (Redis 6+)
# user default on >Your_Very_Strong_#Redis_Password_2025 ~* +@all

Restart after changes:

# Ubuntu/Debian
sudo systemctl restart redis-server

# RHEL family
sudo systemctl restart redis

Persistence: RDB and AOF

Redis supports RDB snapshots and AOF (Append Only File). RDB is compact and fast to restore; AOF provides better durability. Many teams use both.

# RDB snapshot intervals (default examples)
save 900 1
save 300 10
save 60 10000

# Enable AOF for durability
appendonly yes
appendfsync everysec

Ensure your filesystem and IOPS can sustain everysec. For write-heavy workloads, monitor latency and consider no-appendfsync-on-rewrite yes.

Memory Management and Eviction

Set a memory ceiling and a sensible eviction policy for caches:

# Cap memory usage (example 2GB)
maxmemory 2gb

# Evict least recently used keys across all keys
maxmemory-policy allkeys-lru

Choose policies thoughtfully: volatile-lru only evicts keys with expiries; noeviction will error on memory pressure (good for strict use cases).

Firewall and Network Access

For local-only caching (same server as the app), keep default binding and skip firewall changes. For remote access, restrict to specific IPs.

Ubuntu/Debian (UFW)

# Allow only a trusted app server to connect
sudo ufw allow from 203.0.113.10 to any port 6379 proto tcp

# If you must open publicly (not recommended)
sudo ufw allow 6379/tcp

RHEL/CentOS/AlmaLinux (firewalld)

# Allow a specific source IP
sudo firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="203.0.113.10" port protocol="tcp" port="6379" accept'
sudo firewall-cmd --reload

# Or (less safe) open the port
sudo firewall-cmd --permanent --add-port=6379/tcp
sudo firewall-cmd --reload

Test Redis Functionality

Validate end-to-end operations and performance after configuration updates.

# Basic auth test (if password set)
redis-cli -a 'Your_Very_Strong_#Redis_Password_2025' ping

# Simple workload test
redis-benchmark -q -n 10000 -c 50

Check logs for warnings:

journalctl -u redis-server -e --no-pager   # Ubuntu/Debian
journalctl -u redis -e --no-pager          # RHEL family

Production Hardening Checklist

  • Run Redis as its dedicated user (default packages do this)
  • Restrict network exposure: bind to localhost or private IP; firewall to trusted sources
  • Set a strong password or ACLs; rotate secrets regularly
  • Set vm.overcommit_memory=1 to prevent fork failures
  • Consider disabling Transparent Huge Pages (THP) for stable latency
  • Increase open files limit and watch memory fragmentation
  • Back up dump.rdb and/or appendonly.aof and test restore
  • Monitor with INFO, Prometheus exporters, alerts on memory/latency/evictions
# Overcommit memory (runtime + persist)
echo 'vm.overcommit_memory=1' | sudo tee /etc/sysctl.d/99-redis.conf
sudo sysctl --system

# Disable THP (runtime; make persistent via GRUB or a systemd unit)
echo never | sudo tee /sys/kernel/mm/transparent_hugepage/enabled

To raise open files limit, consider a systemd drop-in with LimitNOFILE, then run systemctl daemon-reload and restart Redis.

Use Redis with WordPress, PHP, and Apps

For PHP apps, the phpredis extension is fast and stable.

# Ubuntu/Debian
sudo apt install -y php-redis
sudo systemctl restart php-fpm || sudo systemctl restart apache2

# RHEL family
sudo dnf install -y php-redis
sudo systemctl restart php-fpm || sudo systemctl restart httpd

WordPress object caching: install a Redis Object Cache plugin, add your Redis host/port/password, and enable persistent object caching. This can cut database queries dramatically and speed up page loads.

If you prefer a managed setup, YouStable’s VPS and Cloud servers can deploy Redis with hardened defaults, firewalls, backups, and WordPress object cache pre-configured—ideal when you want performance without the sysadmin overhead.

Scaling Options: High Availability and Clusters

Redis Sentinel (HA for a Single Primary)

  • Monitors a primary and its replicas
  • Performs automatic failover
  • Apps connect via Sentinel to discover the current primary

Redis Cluster (Sharding + HA)

  • Distributes keys across multiple primary shards
  • Supports replicas and automatic failover
  • Best for very large datasets or high concurrency

Choose Sentinel for simple high availability with one primary; choose Cluster for horizontal scale and high write throughput. Many teams start with Sentinel, then move to Cluster as load grows.

Troubleshooting Common Errors

  • Connection refused: verify service (systemctl status), port, and firewall
  • Cannot connect remotely: ensure bind includes server IP, firewall allows client IP, and password is set
  • OOM or memory errors: adjust maxmemory, eviction policy, and review application cache size
  • MISCONF when writing: AOF or RDB persistence issue; check disk space and file permissions
  • Port already in use: identify with ss -ltnp | grep 6379 and reconfigure the conflict
  • SELinux blocks: on RHEL, review audit.log and add appropriate boolean or policy allowing Redis to bind

Step-by-Step Quick Start Summary

  • Install Redis: apt install redis-server or dnf install redis
  • Enable service: systemctl enable –now redis-server or redis
  • Secure config: set bind, protected-mode, requirepass
  • Enable persistence: RDB + AOF as needed
  • Set maxmemory and an eviction policy
  • Restrict firewall to trusted IPs
  • Test with redis-cli and redis-benchmark
  • Harden kernel settings and monitor

FAQ’s

Is it safe to expose Redis to the internet?

No. Redis should never be publicly accessible. Bind to localhost or a private IP and restrict with a firewall to specific client IPs. Always enable a strong password or ACLs and consider a VPN or private network between app and cache server.

How much RAM does Redis need?

It depends on your dataset and eviction policy. For small WordPress sites, 512 MB–2 GB is common; busy eCommerce or microservices may need 4–32 GB+. Redis holds data in RAM, so plan headroom for overhead, AOF/RDB operations, and fragmentation.

Should I use RDB, AOF, or both?

For pure caching, RDB snapshots alone may be enough. For durable data (sessions, queues), enable AOF with everysec. Many production setups enable both: RDB for quick restores and AOF for better write durability.

How do I make Redis start on boot?

Use systemd. On Ubuntu/Debian: sudo systemctl enable redis-server. On RHEL-based systems: sudo systemctl enable redis. Verify with systemctl is-enabled and check logs with journalctl.

How do I upgrade Redis safely?

Back up dump.rdb and appendonly.aof, read the release notes, and upgrade via your package manager. For production clusters, upgrade replicas first, fail over, then upgrade the former primary. Validate with redis-cli INFO and test client compatibility.

That’s it—you now know how to create Redis on Linux server from scratch, secure it, and tune it for real workloads. If you want experts to deploy and maintain Redis with 24/7 monitoring and backups, YouStable’s managed VPS and Cloud platforms are engineered for that.

Sanjeet Chauhan

Leave a Comment

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

Scroll to Top