Enable Object Caching with Redis on LiteSpeed Server

Object caching plays a crucial role in enhancing WordPress performance by minimizing repeated database queries and serving data faster from memory. For high-traffic sites running on a LiteSpeed web server, implementing Redis as the object caching layer can dramatically reduce server load and improve page response times. In this guide, you’ll learn how to install Redis, configure it for optimal performance, fine-tune your system’s memory settings, and prepare your server for efficient, long-term object caching — all while maintaining compatibility with LiteSpeed Cache and WordPress best practices.

Step 1: Install Redis & PHP Redis Extension

sudo apt update
sudo apt install redis lsphp83-redis

Check Redis service status:

sudo systemctl status redis

Step 2: Configure Redis Service

Edit the Redis systemd service file:

sudo vim /etc/systemd/system/redis.service

Add or modify the following under [Service]:

[Service]
Type=forking
ExecStart=/usr/bin/redis-server /etc/redis/redis.conf
PIDFile=/run/redis/redis-server.pid
ExecStartPost=/bin/sh -c "echo $MAINPID > /var/run/redis/redis.pid"
TimeoutStopSec=0
Restart=always
User=redis
Group=redis
RuntimeDirectory=redis
RuntimeDirectoryMode=2755

Reload and restart the service:

sudo systemctl daemon-reload
sudo systemctl restart redis-server

Check logs:

sudo cat /var/log/redis/redis-server.log

Step 3: Tweak Memory Settings

A. Fix Background Save Issues

Add to /etc/sysctl.conf:

vm.overcommit_memory = 1

Apply

sudo sysctl -p

B. Disable Transparent Huge Pages (THP)

Create a systemd service:

sudo vim /etc/systemd/system/disable-transparent-huge-pages.service

Add:

[Unit]
Description=Disable Transparent Huge Pages (THP)
DefaultDependencies=no
After=sysinit.target local-fs.target
Before=redis.service

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

[Install]
WantedBy=basic.target

Enable & verify:

sudo systemctl daemon-reload
sudo systemctl start disable-transparent-huge-pages
sudo systemctl enable disable-transparent-huge-pages
cat /sys/kernel/mm/transparent_hugepage/enabled

Step 4: Tune Redis Performance

A. Tune with tuned-adm (if installed)

Create custom profile:

cd /etc/tuned
sudo mkdir nothp_profile
cd nothp_profile

Create tuned.conf:

[main]
include=throughput-performance
[vm]
transparent_hugepages=never

Apply:

tuned-adm profile nothp_profile

Check the the setting is enabled:

cat /sys/kernel/mm/transparent_hugepage/enabled

Output:

always madvise [never]
sudo reboot

Step 5: Redis Configuration

Edit Redis config file:

sudo vim /etc/redis/redis.conf

Add:

maxmemory 256mb
maxmemory-policy allkeys-lru

Step 6: Enable Redis Unix Socket (Optional)

Modify Redis service file:

Group=nogroup
RuntimeDirectoryMode=0775

Apply changes:

sudo systemctl daemon-reload
sudo systemctl restart redis-server

Test:

sudo nc -U /var/run/redis/redis.sock
# Type `info` then `quit`

Step 7: Restart Services

Gracefully reload OpenLiteSpeed:

sudo /usr/local/lsws/bin/lswsctrl reload

Or via WebAdmin → Actions → Restart Detached PHP Processes