How7o
  • Home
  • Tools
  • Prank Screens
  • Learn
  • Blog
  • Contact
Reading: How to Install and Configure Redis on Ubuntu (for Laravel & WordPress)
Share
How7oHow7o
Font ResizerAa
  • OS
Search
  • Home
  • Tools
  • Prank Screens
  • Learn
  • Blog
  • Contact
Follow US
© 2024–2026 How7o. All rights reserved.
How7o > Free Laravel, PHP, WordPress & Server Tutorials > Server Management > How to Install and Configure Redis on Ubuntu (for Laravel & WordPress)
Server Management

How to Install and Configure Redis on Ubuntu (for Laravel & WordPress)

how7o
By how7o
Last updated: May 23, 2026
10 Min Read
Install and configure Redis on Ubuntu for Laravel and WordPress
SHARE

To install Redis on Ubuntu and wire it into a PHP stack (Laravel, WordPress, plain PHP), install the redis-server and php-redis packages, bind Redis to localhost with a password, and update your app’s environment to point at it. Redis takes over from the default file-based cache and slots in as a queue/session/object-cache driver — the same install supports all three use cases simultaneously.

Contents
  • TL;DR
  • Step 1 — install
  • Step 2 — secure Redis
  • Step 3 — install the PHP extension
  • Step 4 — Laravel setup
  • Step 5 — WordPress setup
  • Step 6 — UFW and SELinux
  • Step 7 — monitor and tune
  • Common failures
  • Frequently asked questions
  • Related guides
  • References

Last verified: 2026-05-17 on Ubuntu 24.04 with Redis 7.x, PHP 8.3, Laravel 11, and WordPress 6.5.

TL;DR

sudo apt update
sudo apt install -y redis-server php-redis

# Secure: set a password, ensure it binds to localhost
# Edit /etc/redis/redis.conf (details below)

sudo systemctl enable --now redis-server
redis-cli ping
# PONG

Step 1 — install

sudo apt update
sudo apt install -y redis-server

Ubuntu 22.04 ships Redis 6.x; Ubuntu 24.04 ships 7.x. Both are recent enough for any current PHP framework. If you need the absolute latest, the upstream redis.io APT repository has it, but the distro package is fine for production use.

The install starts the service automatically and binds Redis to 127.0.0.1:6379. Verify:

redis-cli ping
# PONG

systemctl is-active redis-server
# active
Install Redis on Ubuntu — apt install, secure with password, wire into Laravel/WordPress

Step 2 — secure Redis

The default install binds to localhost only — good. But it has no password by default, which means any local user on the box can read or modify cached data. Add one:

sudo nano /etc/redis/redis.conf

Find and edit these directives:

bind 127.0.0.1 ::1                              # localhost only — leave as-is unless multi-host
protected-mode yes                              # refuse external connections when no auth set
requirepass YourStrongRandomPasswordHere        # uncomment and replace
maxmemory 256mb                                 # cap memory use (tune for your box)
maxmemory-policy allkeys-lru                    # evict least-recently-used when full
appendonly yes                                  # persist to disk (AOF)
appendfsync everysec                            # sync to disk every second (safe + fast)

Generate the password with openssl rand -base64 32. Restart Redis to apply:

sudo systemctl restart redis-server

# Verify auth is required
redis-cli ping
# (error) NOAUTH Authentication required.

# Authenticate first
redis-cli -a 'YourStrongRandomPasswordHere' ping
# PONG

Step 3 — install the PHP extension

sudo apt install -y php-redis

# Restart PHP-FPM (and Apache if mod_php)
sudo systemctl reload php8.3-fpm
sudo systemctl reload apache2        # only if using mod_php

# Confirm
php -m | grep -i redis
# redis

php-redis is the native C extension. It’s faster than Predis (the PHP-only alternative) and is the default for Laravel and WordPress object-cache packages. Predis is still useful when you can’t install PHP extensions — managed hosting, etc. — but on a VPS where you have root, install the native one.

Step 4 — Laravel setup

Update your .env:

REDIS_HOST=127.0.0.1
REDIS_PORT=6379
REDIS_PASSWORD=YourStrongRandomPasswordHere
REDIS_CLIENT=phpredis

CACHE_STORE=redis
SESSION_DRIVER=redis
QUEUE_CONNECTION=redis

# Use a separate logical database per workload (optional but tidy)
REDIS_DB=0
REDIS_CACHE_DB=1

Then clear cached config:

php artisan config:clear

# In production, re-cache after .env changes
php artisan config:cache

# Reload PHP-FPM so long-lived workers pick up the new config
sudo systemctl reload php8.3-fpm

Test from Tinker:

php artisan tinker

# Inside Tinker
Cache::put('test', 'hello', 60);
Cache::get('test');     // "hello"

# And via redis-cli — should see the key
redis-cli -a '...' KEYS '*test*'

Step 5 — WordPress setup

Install the Redis Object Cache plugin (or via WP-CLI: wp plugin install redis-cache --activate).

Add the connection details to wp-config.php above the “That’s all, stop editing!” line:

// wp-config.php
define( 'WP_REDIS_HOST',     '127.0.0.1' );
define( 'WP_REDIS_PORT',     6379 );
define( 'WP_REDIS_PASSWORD', 'YourStrongRandomPasswordHere' );
define( 'WP_REDIS_DATABASE', 2 );   // separate DB from Laravel etc.
define( 'WP_REDIS_PREFIX',   'wp:' );

Then in the WP admin, go to Settings → Redis and click Enable Object Cache. The plugin drops in wp-content/object-cache.php (the WordPress drop-in convention) and starts serving cached objects from Redis.

Confirm with wp redis status (WP-CLI) or by watching redis-cli MONITOR while you browse the admin.

Step 6 — UFW and SELinux

Since Redis binds to localhost, no firewall change is needed for a single-server install — port 6379 is never reachable from outside the box. If UFW is on, leave it that way.

For a multi-server setup where Redis is on a separate host and accessed over a private network, bind Redis to the private IP (bind 10.0.0.5 127.0.0.1), open the port to just the trusted IPs (sudo ufw allow from 10.0.0.10 to any port 6379), and absolutely use requirepass — Redis on a public network without auth is a freshly-rooted server waiting to happen.

Step 7 — monitor and tune

# Server stats
redis-cli -a '...' INFO server
redis-cli -a '...' INFO memory
redis-cli -a '...' INFO stats

# Live command stream (Ctrl+C to exit) — verifies traffic
redis-cli -a '...' MONITOR

# Slow queries (over 10ms by default)
redis-cli -a '...' SLOWLOG GET 10

# Database size
redis-cli -a '...' DBSIZE

The metrics that matter:

  • used_memory_human in INFO memory — current memory use. Compare to maxmemory.
  • evicted_keys in INFO stats — keys dropped due to maxmemory. Steady eviction = cache too small; bursty = ok.
  • keyspace_hits / keyspace_misses — hit rate. Anything under 80% on a steady-state app is worth investigating.

Common failures

  • “NOAUTH Authentication required” — you set a password but the client (Laravel, WordPress, redis-cli) doesn’t have it. Re-check REDIS_PASSWORD / WP_REDIS_PASSWORD.
  • “DENIED Redis is running in protected mode” — you’re trying to connect from a different host but haven’t set a password or adjusted bind. Set requirepass and add the listening IP to bind.
  • Out-of-memory crashes — Redis hit the system OOM killer because maxmemory wasn’t set. Set it to something less than physical RAM so Redis’s own LRU eviction kicks in first.
  • Slow performance — check SLOWLOG GET; KEYS * calls in application code (instead of SCAN) lock the server for the duration of the scan. Find and fix.

Frequently asked questions

Redis vs Memcached for PHP caching — when does each fit?

Both are in-memory key/value stores. Memcached is simpler — string values only, no persistence, sharding via the client. Redis supports rich data types (hashes, lists, sets, sorted sets, streams), optional persistence to disk, pub/sub, Lua scripting, atomic transactions, and key expiry semantics that Memcached lacks. For Laravel queues, WordPress object cache, or anything beyond plain string caching, Redis is the obvious pick. For a tiny session-cache use case with no other needs, Memcached is fine and a bit lighter.

Why does redis-cli ping work but Laravel still uses the file cache?

Laravel reads cache configuration at boot and (in production) from bootstrap/cache/config.php. After changing .env, you need to refresh the cached config: php artisan config:clear (development) or php artisan config:cache (production). If you’re running PHP-FPM, also reload it (sudo systemctl reload php8.3-fpm) — long-lived FPM workers keep the old config in memory until they recycle.

Should I run Redis on the same server as the web app, or on a separate host?

For a single-server setup with one web app, run it on the same box — it’s a local Unix-socket connection, latency is sub-millisecond, and Redis’s memory footprint is small. For multi-server setups where multiple web nodes share a cache, run Redis on its own host on the private network. Never expose Redis to the public internet — historical default config has no auth, and there are well-known wormable RCE patterns against unauthenticated Redis.

How much RAM should I dedicate to Redis?

Set maxmemory to half of available RAM if Redis is the dominant workload, less if it shares the box with MySQL/PHP. With maxmemory-policy allkeys-lru, Redis evicts least-recently-used keys when it hits the limit — cache use cases can run at full memory without issues. For workloads where every key must persist (queue, session store), pick a policy like noeviction and size memory so you never reach the limit.

Related guides

  • How to Install Laravel
  • How to Install PHP on Ubuntu
  • How to Install MySQL on Ubuntu
  • How to Create a Login and Registration System in Laravel
  • How to Harden a Fresh Ubuntu VPS

References

Redis documentation: redis.io/docs. PhpRedis extension: github.com/phpredis/phpredis. Redis Object Cache for WordPress: github.com/rhubarbgroup/redis-cache. Laravel cache documentation: laravel.com/docs/cache.

TAGGED:cachingLaravelperformancephpredisUbuntu

Sign Up For Daily Newsletter

Be keep up! Get the latest breaking news delivered straight to your inbox.
[mc4wp_form]
By signing up, you agree to our Terms of Use and acknowledge the data practices in our Privacy Policy. You may unsubscribe at any time.
Share This Article
Facebook Copy Link Print
Previous Article Harden a fresh Ubuntu VPS with UFW, Fail2Ban, and SSH key auth How to Harden a Fresh Ubuntu VPS: UFW + Fail2Ban + SSH Key Auth
Next Article Nginx as a reverse proxy for a Node.js app on Ubuntu How to Set Up Nginx as a Reverse Proxy for Node.js on Ubuntu
Leave a Comment

Leave a Reply Cancel reply

You must be logged in to post a comment.

FacebookLike
XFollow
PinterestPin
InstagramFollow
Most Popular
Run Laravel queue workers with Supervisor
How to Run Laravel Queue Workers in Production with Supervisor
May 23, 2026
Nginx as a reverse proxy for a Node.js app on Ubuntu
How to Set Up Nginx as a Reverse Proxy for Node.js on Ubuntu
May 23, 2026
Install and configure Redis on Ubuntu for Laravel and WordPress
How to Install and Configure Redis on Ubuntu (for Laravel & WordPress)
May 23, 2026
Harden a fresh Ubuntu VPS with UFW, Fail2Ban, and SSH key auth
How to Harden a Fresh Ubuntu VPS: UFW + Fail2Ban + SSH Key Auth
May 23, 2026
Set up Let's Encrypt SSL with Certbot on Ubuntu
How to Set Up Let’s Encrypt SSL with Certbot on Ubuntu (Apache & Nginx)
May 23, 2026

You Might Also Like

Laravel Eloquent orderBy — code snippet sorting posts by id descending with arrow icons
Web Development

How to Use orderBy in Laravel Eloquent (with Examples)

6 Min Read
Debug PHP like console.log using error_log and server logs
Web Development

How to Debug in PHP Like console.log (echo, error_log, WordPress debug.log)

6 Min Read
aaPanel domain and Let's Encrypt SSL setup — secure the control panel
Server Management

How to Access aaPanel with a Domain and Let’s Encrypt SSL

8 Min Read
Laravel validator exists rule checking a post_id against the posts table
Web Development

How to Use the Laravel Validator Exists Rule

6 Min Read
How7o

We provide tips, tricks, and advice for improving websites and doing better search.

Tools

  • Age Calculator
  • Word Counter
  • Image Upscaler
  • Password Generator
  • QR Code Generator
  • See all tools→

Pranks

  • Fake Blue Screen Prank
  • Hacker Typer
  • Fake iMessage Generator
  • Windows XP Crash Prank
  • Windows 11 Update Prank
  • See all prank screens →

Company

  • About Us
  • Blog
  • Contact
  • Privacy Policy
  • Terms of Service
  • Sitemap
© 2024–2026 How7o. All rights reserved.
Welcome Back!

Sign in to your account

Username or Email Address
Password

Lost your password?