To use Redis on a Linux server, install it via your package manager, enable the service at boot, secure access (bind, firewall, password/ACL, TLS), configure persistence and memory eviction in redis.conf, and connect using redis click or your app’s client.
This guide shows installation, configuration, tuning, and WordPress caching step by step. If you’re wondering how to use Redis on Linux server environments reliably and securely, you’re in the right place.
Below, I’ll cover installation on popular distros, production grade configuration, performance tuning, monitoring, and how to integrate Redis with WordPress and other apps using best practices I apply every day on real servers.
What is Redis and Why Use it?
Redis is an in memory data store known for extreme speed and low latency. It’s widely used as a cache, message broker, session store, rate limiter, and task queue backend.
On Linux servers, Redis can accelerate web apps, APIs, and databases (e.g., MySQL/PostgreSQL) by offloading frequently accessed data into RAM.
Prerequisites and Quick Checklist
- Linux server with sudo/root access (Ubuntu/Debian, Rocky/Alma/RHEL, or similar)
- OpenSSH access and a terminal
- Firewall control (UFW or firewalld)
- Basic understanding of editing config files (redis.conf)
- Optional: domain/SSL certs if enabling TLS for remote access
Install Redis on Linux
Ubuntu/Debian (APT)
Ubuntu 20.04+ and Debian 11+ include stable Redis in their repositories. For most use cases, this is sufficient.
sudo apt update
sudo apt install -y redis-server
redis-server --version
On Ubuntu, the service is typically named redis-server. Debian may use the same name. The default config lives at /etc/redis/redis.conf.
RHEL/CentOS/Rocky/Alma (YUM/DNF)
On RHEL-family distros, install via EPEL or the distro’s Redis package.
# Enable EPEL if needed
sudo dnf install -y epel-release || sudo yum install -y epel-release
# Install Redis
sudo dnf install -y redis || sudo yum install -y redis
redis-server --version
Config is typically at /etc/redis/redis.conf and the service is named redis.
Build From Source (Optional)
If you need the newest features (e.g., latest eviction improvements, modules), compile Redis from source. This is common on performance-sensitive stacks.
sudo apt update && sudo apt install -y build-essential tcl wget
# or: sudo dnf groupinstall -y "Development Tools"; sudo dnf install -y tcl wget
wget http://download.redis.io/redis-stable.tar.gz
tar xzf redis-stable.tar.gz
cd redis-stable
make
sudo make install
# Optional test
make test
Then create a systemd service or use the provided utils to set up directories and a redis.conf. For most admins, distro packages are simpler and secure by default.
Start, Enable, and Test Redis
# Start and enable on boot
sudo systemctl enable --now redis-server # Ubuntu/Debian
# or
sudo systemctl enable --now redis # RHEL/Rocky/Alma
# Check status
systemctl status redis-server || systemctl status redis
# Quick test (local)
redis-cli ping
# Output: PONG
By default, Redis binds to 127.0.0.1 for local access. That’s secure for single-server apps, including WordPress on the same host.
Secure Redis for Production
Never expose Redis to the public internet without strict controls. At minimum, use local-only access, strong authentication, firewall rules, and (if needed) TLS for remote clients.
Bind, Protected Mode, Password, and ACLs
Edit /etc/redis/redis.conf (path may vary) and review these directives:
bind 127.0.0.1 ::1
protected-mode yes
# Require authentication (strong passphrase)
requirepass <STRONG_UNIQUE_PASSWORD>
# Optional: fine-grained ACLs (Redis 6+)
# aclfile /etc/redis/users.acl
Restart Redis after changes:
sudo systemctl restart redis-server || sudo systemctl restart redis
TLS Encryption for Remote Access
If clients connect from other servers, enable TLS. Generate or provide certificates, then update redis.conf:
# Disable non-TLS port if you want TLS-only
port 0
tls-port 6379
tls-cert-file /etc/redis/ssl/redis.crt
tls-key-file /etc/redis/ssl/redis.key
tls-ca-cert-file /etc/redis/ssl/ca.crt
tls-auth-clients yes
Clients must support TLS (most official clients do). You can also front Redis with stunnel or an internal private network (e.g., VPC) for isolation.
Firewall Rules
Allow only trusted sources. Examples:
# UFW (Ubuntu/Debian) - allow a single remote host
sudo ufw allow from 203.0.113.10 to any port 6379 proto tcp
# firewalld (RHEL family)
sudo firewall-cmd --permanent --add-rich-rule='rule family="ipv4" \
source address="203.0.113.10/32" port protocol="tcp" port="6379" accept'
sudo firewall-cmd --reload
Persistence and Memory Management
Choose RDB, AOF, or Both
Redis keeps data in RAM, but persistence protects against data loss:
- RDB snapshots: periodic, compact files. Faster restarts, small footprint. Good for cache/session stores.
- AOF (Append Only File): logs every write. More durable, slightly larger I/O overhead. Better for critical datasets.
- RDB + AOF: common middle ground—fast restarts and durability.
# Example RDB snapshot rules (default examples)
save 900 1
save 300 10
save 60 10000
# Enable AOF and modern rewrite mode
appendonly yes
appendfsync everysec
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
maxmemory and Eviction Policy
Set a memory ceiling so Redis never forces the kernel to OOM-kill the process:
maxmemory 2gb
maxmemory-policy allkeys-lru # Alternatives: volatile-lru, allkeys-random, noeviction, etc.
For pure caching, allkeys-lru or allkeys-lfu works well. For session or critical data, consider noeviction but ensure capacity is sufficient.
Linux Performance Tuning for Redis
Kernel and System Settings
- vm.overcommit_memory=1 to avoid memory allocation failures
- Disable Transparent Huge Pages (THP) for consistent latency
- Increase somaxconn for better connection backlogs
- Raise file descriptors if using many connections
# /etc/sysctl.d/99-redis.conf
vm.overcommit_memory=1
net.core.somaxconn=1024
# Apply now
sudo sysctl --system
# Disable THP (temporary until reboot)
echo never | sudo tee /sys/kernel/mm/transparent_hugepage/enabled
echo never | sudo tee /sys/kernel/mm/transparent_hugepage/defrag
# Increase open files for Redis via systemd override
sudo systemctl edit redis-server || sudo systemctl edit redis
# In the editor, add:
# [Service]
# LimitNOFILE=100000
sudo systemctl daemon-reload
sudo systemctl restart redis-server || sudo systemctl restart redis
Validate with redis-benchmark (bundled) or tools like memtier_benchmark to confirm throughput and latency improvements.
Monitoring and Maintenance
- Logs: /var/log/redis/redis-server.log (path varies). Use logrotate for retention.
- INFO command: check memory, clients, CPU, persistence stats.
- SLOWLOG: find slow operations caused by big keys or blocking commands.
- Backups: copy RDB/AOF files regularly (and before upgrades).
- Upgrades: review release notes; backup, then upgrade during maintenance windows.
# Examples
redis-cli INFO memory
redis-cli SLOWLOG GET 10
redis-cli CONFIG GET dir
redis-cli CONFIG REWRITE
Use Redis With Your Applications
WordPress Object Cache (Recommended)
- Install Redis server locally (same host as WordPress) for best latency.
- In WordPress, install the “Redis Object Cache” plugin.
- Set WP_REDIS_PASSWORD in wp-config.php if you enabled requirepass.
- Activate the object cache in the plugin and verify connection.
// wp-config.php
define( 'WP_REDIS_HOST', '127.0.0.1' );
define( 'WP_REDIS_PORT', 6379 );
define( 'WP_REDIS_PASSWORD', '<STRONG_UNIQUE_PASSWORD>' );
define( 'WP_CACHE', true );
Expect faster admin pages, reduced database queries, and snappier user experiences. For high traffic, combine with page caching (e.g., Nginx FastCGI cache) and a CDN.
Other Stacks (PHP, Python, Node.js)
- PHP: predis/predis or phpredis extension
- Python: redis-py
- Node.js: ioredis or node-redis
# redis-cli example
redis-cli -a <PASSWORD> set app:health ok
redis-cli -a <PASSWORD> get app:health
Always use connection pooling, timeouts, and sensible key naming (namespaces like app:env:feature:key). Consider TTLs for cache keys to prevent stale data accumulation.
Troubleshooting Common Issues
- Cannot connect: check bind, port, firewall, and requirepass. Use redis-cli -h HOST -p PORT -a PASSWORD.
- OOM or eviction storms: raise maxmemory, change policy, or reduce dataset size. Monitor INFO memory.
- High latency spikes: disable THP, tune kernel, avoid large Lua scripts or massive keys. Inspect SLOWLOG.
- Data not persisting: ensure AOF/RDB enabled and writable dir. Check permissions and logs.
- TLS handshake failures: validate cert chain, matching CN/SAN, and client support for TLS.
When Managed Hosting Helps
If you prefer not to manage Redis yourself, a managed VPS or cloud server with Redis preconfigured can save hours and reduce risk. At YouStable, our engineers can provision optimized Linux servers with Redis, secure defaults, and continuous monitoring—so you focus on your application, not the plumbing.
Best Practices Summary
- Keep Redis local to the app server whenever possible; otherwise, use TLS and a strict firewall.
- Enable authentication and consider ACLs for multi-app environments.
- Choose the right persistence (RDB/AOF) for your data durability needs.
- Set maxmemory and an eviction policy that matches your workload.
- Tune the OS: overcommit_memory, disable THP, and increase somaxconn.
- Monitor with INFO, SLOWLOG, and external metrics. Back up RDB/AOF regularly.
FAQ’s – Use Redis on Linux Server
Is Redis safe to expose to the internet?
No. Keep Redis behind a firewall and private network. If remote access is required, enforce authentication, restrict source IPs, and enable TLS. Default open access is a critical security risk.
Which is better for persistence: RDB or AOF?
For caching, RDB snapshots are usually enough and start quickly. For higher durability, enable AOF with appendfsync everysec. Many production environments use both for a balance of recovery speed and data safety.
How much RAM should I allocate to Redis?
Set maxmemory below total system RAM, leaving headroom for the OS and other services (typically 50–75% of available memory for Redis if it’s the main workload). Size it to your dataset and eviction policy.
Does Redis need special kernel tuning?
Yes. Set vm.overcommit_memory=1, increase net.core.somaxconn, and disable Transparent Huge Pages. These changes reduce latency spikes and allocation failures under load.
How do I speed up WordPress with Redis?
Install Redis locally, secure it, then add the Redis Object Cache plugin to WordPress. Enable the object cache and confirm it’s connected. Combine with page caching and a CDN for best results. Managed servers from YouStable can set this up for you end-to-end.
With these steps, you can confidently install, secure, and optimize Redis on your Linux server, whether you’re accelerating WordPress, scaling APIs, or building real-time features.