AdminsForum

CyberPanel Websites & OpenLiteSpeed Guides

Guide Redis Object Cache for WordPress on CyberPanel With LiteSpeed Cache

Started by JAY 0 replies 99 views
1JAY
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
#1
Redis Object Cache for WordPress on CyberPanel With LiteSpeed Cache

Page cache (LiteSpeed Cache) serves finished pages to visitors. It doesn't help logged-in users, WooCommerce carts, or the admin area, where every page still runs dozens of database queries. An object cache keeps the results of those queries in memory, so WordPress asks MySQL less often. On CyberPanel the pieces are already on the server; you only have to connect them. We did it on our test site and checked every step.

Step 1: Check Redis is installed and running
CyberPanel 3.0 installed Redis for us during setup. Check yours:
Code:
systemctl is-active redis-server redis-cli ping redis-server --version
We got
Code:
active
,
Code:
PONG
and Redis 7.0.15. If you get "command not found", install it with
Code:
apt install -y redis-server
and start it with
Code:
systemctl enable --now redis-server
.

Make sure it only listens on the server itself:
Code:
ss -ltnp | grep 6379
Ours showed
Code:
127.0.0.1:6379
and
Code:
[::1]:6379
only (
Code:
bind 127.0.0.1 -::1
in
Code:
/etc/redis/redis.conf
). Never open port 6379 to the internet.

Step 2: Check the PHP extension
WordPress talks to Redis through the PHP redis extension, and it has to be loaded in the PHP version your site uses:
Code:
ls /usr/local/lsws/lsphp*/etc/php/*/mods-available/ | grep redis
We found
Code:
50-redis.ini
for all five installed versions (8.1 to 8.5). If yours is missing, install it from Server > PHP > Install Extensions; see installing PHP extensions in CyberPanel.

Step 3: Turn on Object Cache in LiteSpeed Cache
In WordPress admin open LiteSpeed Cache > Cache > Object. Set Object Cache to ON, Method to Redis, Host
Code:
127.0.0.1
, Port
Code:
6379
, and save. Leave username and password empty unless you set a Redis password.

Watch the defaults. Before we changed anything, LiteSpeed Cache was set to Memcached on port
Code:
11211
:
Code:
wp litespeed-option get object-kind -> 0 (0 = Memcached, 1 = Redis) wp litespeed-option get object-port -> 11211
If you only flip the ON switch, it talks to Memcached, not Redis. On CyberPanel that is LiteSpeed's own
Code:
lsmcd
service, which was running on our server too. That works as well, but it isn't what you meant to set up.

We switched it on from SSH with WP-CLI. Each command answers with the saved value, and LiteSpeed Cache writes the drop-in file right away:
[Image: attachment.php?aid=530]

Code:
cd /home/yourdomain.com/public_html sudo -u SITEUSER wp litespeed-option set object-kind 1 sudo -u SITEUSER wp litespeed-option set object-host 127.0.0.1 sudo -u SITEUSER wp litespeed-option set object-port 6379 sudo -u SITEUSER wp litespeed-option set object true
Replace
Code:
SITEUSER
with the site's Linux user (ours is
Code:
cyber2602
; find yours with
Code:
stat -c %U .
). The file
Code:
wp-content/object-cache.php
appeared at once. No WP-CLI yet? See our WordPress install guide.

Step 4: Prove it works
Before:
Code:
redis-cli dbsize
printed . After one page load it printed 39.
Load a few pages and look at the Redis hit counter, then cap the memory:
Code:
# redis-cli info stats | grep keyspace keyspace_hits:105 keyspace_misses:45 # redis-cli config set maxmemory 256mb OK # redis-cli config set maxmemory-policy allkeys-lru OK # redis-cli config rewrite OK # grep -E '^maxmemory' /etc/redis/redis.conf maxmemory 256mb maxmemory-policy allkeys-lru

Code:
for i in 1 2 3; do curl -sk -o /dev/null https://yourdomain.com/?nc=$i; done redis-cli info stats | grep keyspace
We saw
Code:
keyspace_hits:105
and
Code:
keyspace_misses:45
: two out of three lookups were answered from memory instead of MySQL. The hits climb as the site gets traffic.

Step 5: Give Redis a memory limit
Out of the box ours had
Code:
maxmemory_human:0B
, which means no limit. On a small VPS a busy cache can grow until the server starts swapping. Set a cap and let Redis drop the least-used keys when it's full:
Code:
redis-cli config set maxmemory 256mb redis-cli config set maxmemory-policy allkeys-lru redis-cli config rewrite
Code:
config rewrite
saves both lines into
Code:
/etc/redis/redis.conf
, so they survive a restart. 128 to 256 MB is plenty for a few normal WordPress sites.

Several sites on one server
LiteSpeed Cache puts a long per-site prefix in front of every key, so two sites don't read each other's entries. But clearing the cache is wider than one site. We put a test key in Redis database 5, then ran:
Code:
sudo -u cyber2602 wp cache flush redis-cli dbsize; redis-cli -n 5 dbsize
Database 0 dropped from 39 keys to 5 (rebuilt on the next request); the key in database 5 survived. A flush clears the whole database number the site uses, so sites sharing database 0 wipe each other's cache every time one of them purges. Give each site its own Redis Database ID (0 to 15) in LiteSpeed Cache > Cache > Object, or with:
Code:
sudo -u SITEUSER wp litespeed-option set object-db_id 2
We moved our site to database 2; after one page load
Code:
redis-cli -n 2 dbsize
showed the 39 keys there.
For the same reason, don't run
Code:
redis-cli flushall
on a shared server: it empties every site's cache at once.

Also know that Redis on CyberPanel has no password by default (
Code:
grep -c ^requirepass /etc/redis/redis.conf
printed for us). Anything running on the server can read the cache. That's fine on a server that only hosts your own sites. If you host other people, set a password (
Code:
requirepass
in
Code:
redis.conf
, then the same password in LiteSpeed Cache).

Common problems
  • Object cache not working (dbsize stays 0): Redis is stopped (
    Code:
    systemctl restart redis-server
    ) or the method is still Memcached. Check
    Code:
    wp litespeed-option get object-kind
    .
  • LiteSpeed Cache says the Redis extension is missing: the extension isn't loaded in the PHP version this site uses. Install it, then restart PHP with
    Code:
    killall lsphp
    .
  • Site shows old content after an edit: purge from the LiteSpeed Cache toolbar or run
    Code:
    wp cache flush
    as the site user.
  • Everything got slower: rare, but it happens when Redis is out of memory and constantly evicting. Check
    Code:
    redis-cli info memory | grep human
    and raise
    Code:
    maxmemory
    .
  • Want to turn it off:
    Code:
    wp litespeed-option set object false
    , or the switch in LiteSpeed Cache. If you ever remove the plugin and pages break, check for a leftover
    Code:
    wp-content/object-cache.php
    and delete it.

More CyberPanel guides
Tested on CyberPanel 3.0 (build 8, OpenLiteSpeed edition) on Ubuntu 24.04, October 2026. Menu names can change slightly between versions.

Attached Files

Image(s)
   
Reply
Possibly Related Threads…matched by title
Replies:0Views:7
Replies:0Views:13
Replies:0Views:16
Replies:0Views:13
Replies:0Views:103

Users browsing this thread: 1 Guest(s)
Forum Jump: