Skip to content

Persistent object cache on cPanel: Redis or Memcached for WordPress

WordPress Site Health says you should use a persistent object cache and the site runs on cPanel. Which backend to install, how to stand it up per account, how to wire the drop-in, and how to prove the cache is persistent and hitting.

If Site Health is showing “You should use a persistent object cache” on a cPanel server, install Redis. Not because it is faster — for the get-and-set traffic WordPress generates the two are indistinguishable — but because the WordPress half of the decision is lopsided: the Redis drop-in is maintained and the Memcached drop-ins are not. Pick Memcached only when the extension is already installed for your PHP version and your cache plugin already speaks it. The rest of this article stands the chosen backend up per account and proves the cache is genuinely persistent.

What you’ll accomplish

  • Decide between Redis and Memcached on the grounds that actually differ on a shared cPanel box: drop-in maintenance, isolation, and behaviour when the cache fills.
  • Install a per-account cache container with ea-podman, reached over a Unix socket in the account’s home with no TCP port exposed.
  • Install the matching PHP extension for the account’s ea-php build and wire wp-config.php to that socket.
  • Cap memory so a full cache evicts instead of rejecting writes.
  • Prove from the shell that the cache survives a PHP process, a service restart, and a reboot.

Prerequisites

WordPress 6.1 or newer — the release that added the persistent object cache Site Health check — on PHP 8.1 or later, with WP-CLI available as wp. Root access to run dnf, plus shell access to the cPanel account itself.

The container path needs a cPanel & WHM server on AlmaLinux, Rocky Linux, or Ubuntu with EasyApache 4 containers available. Per cPanel’s own documentation, the account must have the Normal Shell option in WHM’s Manage Shell Access interface — Jailed Shell cannot use the container — and CloudLinux with CageFS is not supported. On those servers you are back to a host-wide instance, and the isolation section below is the part to read twice.

One naming point first, because it is where most guides go wrong. There are two Memcached PHP extensions: memcache (no d, the older one) and memcached (with d, built on libmemcached). cPanel maintains packages for the second across the current series — ea-php80-php-memcached through ea-php85-php-memcached — and stopped building the first after PHP 7.4. There is no ea-php83-php-memcache, which rules out the classic Memcached Object Cache drop-in on PHP 8. Do not assume the Redis extension either; check what your repositories actually offer.

How it works

WordPress calls wp_cache_get() and wp_cache_set() constantly — for the autoloaded options array, every transient, every term, every chunk of post meta. By default those calls land in WP_Object_Cache, a plain PHP array created when the request starts and destroyed when it ends. It deduplicates lookups within one render and does nothing between requests. That is what “non-persistent” means, and why a site with a fat alloptions row re-queries MySQL on every hit.

Two-column request path diagram: without a persistent object cache, wp_cache_get finds an empty in-process array and every lookup falls through to MySQL; with the object-cache.php drop-in loaded, wp_cache_get reaches Redis or Memcached over a Unix socket and the cache stays warm after the PHP worker exits

A drop-in changes that. wp-settings.php loads wp-content/object-cache.php before plugins and the theme, and that file replaces WP_Object_Cache with one that talks to an external store. The same calls now cross a socket instead of hitting an empty array, and the values outlive the PHP worker.

The Site Health check fires on thresholds, not on principle: 500 autoloaded options, 100,000 bytes of autoloaded option data, or 1,000 rows in posts, comments, options, terms, or users. If you are seeing the notice, at least one of those numbers is real.

Isolation is the decision, not throughput

On a single-tenant box the two are interchangeable. On a shared cPanel host they are not.

Side-by-side isolation diagram: on the left three cPanel accounts each reach their own Redis container through a redis.sock at mode 0700 in their own home, so file permissions block cross-account access; on the right three accounts share one Memcached on 127.0.0.1:11211 with a flat keyspace, no per-account auth, and a flush that empties everyone's keys

cPanel ships both as container-based EasyApache 4 packages — ea-redis62 (Redis 6.2) and ea-memcached16 (Memcached 1.6) — and both install per account, creating a Unix socket inside ~/ea-podman.d/. The socket is owned by the account, and another user’s connect() is refused by the kernel. Done that way either backend isolates properly, because the isolation comes from file permissions rather than from anything the cache enforces.

The difference appears the moment you deviate. One host-wide Memcached on 127.0.0.1:11211 has a flat keyspace and no per-account authentication. WP_CACHE_KEY_SALT stops two sites reading each other’s keys but does not scope a flush: wp_cache_flush() maps to flush_all, which empties the whole instance, so one account clearing its cache cold-starts everyone. Shared Redis is only marginally better — 16 numbered databases and, from Redis 6, per-user ACLs — because the drop-in issues FLUSHDB by default, so two sites in database 0 collide the same way. Separate databases, or separate containers, or you have not separated anything.

Eviction, and what a full cache does to WordPress

Memcached uses slab allocation: memory is carved into fixed-size classes and evicted LRU within a class, so a cache can evict aggressively while reporting free memory overall. The default limit is 64 MB, small for a busy WordPress install.

Redis is simpler and more dangerous by default. maxmemory defaults to 0 — no limit — and maxmemory-policy defaults to noeviction; cPanel’s shipped redis.conf sets neither. An unbounded Redis grows until the host’s OOM killer picks something. A bounded one under noeviction returns OOM command not allowed when used memory > 'maxmemory' on every write, which surfaces in WordPress as a cache that reads fine and never updates. Set maxmemory and allkeys-lru and the failure mode becomes “the cache gets smaller”. The Redis eviction reference covers the other policies.

Step-by-step

1. Confirm the site really has no persistent object cache. Run this in the document root before changing anything:

wp cache type
ls -l wp-content/object-cache.php
Default
ls: cannot access 'wp-content/object-cache.php': No such file or directory

Default plus a missing drop-in is the starting point this article assumes. Anything else means you are debugging, not building.

2. Check what your repositories actually offer. As root:

dnf list --available 'ea-php8*-php-redis' 'ea-php8*-php-memcached'

The ea-php8*-php-memcached packages are cPanel-maintained and should be listed. If nothing matches for redis, dnf prints Error: No matching Packages to list, and step 6 builds it with PECL.

3. Install the server package as root. This puts the container definition on the host; it starts nothing:

dnf install -y ea-redis62
rpm -q ea-redis62 ea-podman
ea-redis62-6.2.23-1.el8.cpanel.x86_64
ea-podman-1.0-...

For Memcached the package is ea-memcached16, and the rest of the procedure has the same shape.

4. Create the account’s container. Set Normal Shell in WHM first, then run this as the account, not as root:

/usr/local/cpanel/scripts/ea-podman install ea-redis62
/usr/local/cpanel/scripts/ea-podman containers
Adding a ea-redis62 instance for “siteA” …
 … done!
ea-redis62.siteA.01

Note the container name; every later command uses it. Confirm the socket:

ls -l ~/ea-podman.d/ea-redis62.siteA.01/

You want redis.sock plus a redis.conf you own at mode 0640. The shipped config sets unixsocketperm 700 and the package publishes no ports, so nothing listens on TCP.

5. Cap memory and set the eviction policy. Still as the account:

cd ~/ea-podman.d/ea-redis62.siteA.01
printf 'maxmemory 256mb\nmaxmemory-policy allkeys-lru\n' >> redis.conf
/usr/local/cpanel/scripts/ea-podman restart ea-redis62.siteA.01
podman exec ea-redis62.siteA.01 redis-cli -s /socket_dir/redis.sock CONFIG GET maxmemory-policy
maxmemory-policy
allkeys-lru

redis-cli lives inside the container, so Redis-level commands go through podman exec. Inside the container the socket is /socket_dir/redis.sock; on the host it is the path from step 4.

6. Install the PHP extension. As root, for an account on ea-php83:

dnf install -y ea-php83-php-redis
/opt/cpanel/ea-php83/root/usr/bin/php -m | grep -x redis
redis

If no package exists, build it with /opt/cpanel/ea-php83/root/usr/bin/pecl install redis, pressing Enter through the igbinary, lzf, zstd and msgpack prompts, then add extension=redis.so for that version through MultiPHP INI Editor. Either way, reload PHP-FPM:

/scripts/restartsrv_apache_php_fpm

7. Point WordPress at the socket. Add these above the /* That's all, stop editing! */ line of wp-config.php:

define( 'WP_REDIS_SCHEME', 'unix' );
define( 'WP_REDIS_PATH', '/home/siteA/ea-podman.d/ea-redis62.siteA.01/redis.sock' );
define( 'WP_REDIS_PREFIX', 'siteA_prod:' );
define( 'WP_REDIS_MAXTTL', 86400 );

WP_REDIS_PREFIX keeps staging and production apart if they ever share a store, and replaces the older WP_CACHE_KEY_SALT. WP_REDIS_MAXTTL caps keys that would otherwise never expire.

8. Install the drop-in. The Redis Object Cache plugin writes and manages wp-content/object-cache.php — do not copy that file by hand:

wp plugin install redis-cache --activate
wp redis enable
wp redis status
Status: Connected
Client: PhpRedis
Drop-in: Valid
Disabled: No

Connected plus Valid is the pass. Drop-in: Invalid means another plugin owns the file.

Validate it works

Confirm WordPress is using an external cache at all:

wp cache type
wp eval 'var_dump( wp_using_ext_object_cache() );'
Redis
bool(true)

Then prove persistence, the claim Site Health is making. Two WP-CLI invocations are two PHP processes, and a non-persistent cache cannot pass this:

wp cache set sh_probe alive stackharbor 300
wp cache get sh_probe stackharbor
Success: Set object 'sh_probe' in group 'stackharbor'.
alive

Now show real traffic reading the cache, not just your probe:

RC="podman exec ea-redis62.siteA.01 redis-cli -s /socket_dir/redis.sock"
$RC INFO stats | grep -E 'keyspace_hits|keyspace_misses|evicted_keys'
curl -s -o /dev/null https://example.com/
$RC INFO stats | grep keyspace_hits

keyspace_hits must climb across the page load. If only keyspace_misses moves, something is flushing between requests. A non-zero evicted_keys this early means maxmemory is too low for the working set.

Confirm the keys are yours and the store survives a PHP restart:

$RC --scan --pattern 'siteA_prod:*' | head -5
/scripts/restartsrv_apache_php_fpm
$RC DBSIZE

DBSIZE stays non-zero after PHP restarts, because the cache is not in PHP.

Finally, the check that matters most on a public IP. An unauthenticated Redis or Memcached reachable from the internet is a server takeover, not a performance bug, so confirm nothing listens on TCP:

ss -lntp | grep -E ':6379|:11211'

No output is the correct result. 0.0.0.0:6379 or 0.0.0.0:11211 means a host-wide instance rather than the container: bind it to 127.0.0.1 or a Unix socket, set requirepass or a Redis ACL user, and confirm the port is blocked at the firewall before going further.

Troubleshooting

  • Site Health still says you should use a persistent object cache. Check wp eval 'var_dump( wp_using_ext_object_cache() );' first. bool(false) with the drop-in in place means the extension is missing for the PHP version the site actually runs — the drop-in exits quietly rather than fataling — or WP_REDIS_DISABLED is true, or OPcache is still serving the old file, which /scripts/restartsrv_apache_php_fpm clears. bool(true) means you are reading a cached result: reload Tools, Site Health, Status rather than the dashboard widget.

  • A stale object-cache.php outlives the uninstall. Deleting the plugin directory does not remove the drop-in, and WordPress keeps loading it — usually as a fatal error, sometimes as a cache that stores nothing. Remove it in order: wp redis disable, confirm with ls -l wp-content/object-cache.php, then remove the plugin. If the plugin is already gone, delete the file by hand.

  • One account’s flush empties another account’s cache. A shared Memcached on 127.0.0.1:11211 working as designed: wp cache flush becomes flush_all, which is instance-wide, and prefixes do not scope it. Shared Redis with two sites in database 0 behaves the same, because the drop-in flushes with FLUSHDB. The fix is a separate instance per account — what the ea-podman container gives you — or at minimum a distinct WP_REDIS_DATABASE per site.

  • Connection refused right after a restart. The socket file is recreated when the container restarts, and any PHP worker holding the old one gets Connection refused. Check podman ps, then systemctl --user status container-ea-redis62.siteA.01. No such unit means the account’s user manager is not running — see the next item. Restart with /usr/local/cpanel/scripts/ea-podman restart ea-redis62.siteA.01, then reload PHP-FPM so workers reconnect.

  • The cache never comes back after a reboot. Rootless containers run under the account’s own systemd --user manager, which stops when the user logs out. ea-podman runs loginctl enable-linger when it creates the first container, so verify rather than assume: loginctl show-user siteA --property=Linger must print Linger=yes. If it prints no, enable it as root and restart the container. Nothing in WHM’s Service Manager watches these containers, so no cPanel process restarts them for you.

When this is the wrong approach

If the notice is the only symptom and the site is anonymous traffic on a handful of pages, an object cache is not the first move — a page cache is, and the difference between the two layers decides which symptom you are treating. An object cache pays off on logged-in traffic, WooCommerce carts, and admin screens, where a page cache cannot help.

Skip the container path on CloudLinux with CageFS, on Jailed Shell accounts, and wherever you do not have root. cPanel does not support containers there, and the alternative is a host-wide instance whose isolation you build yourself.

A local socket also stops making sense once WordPress runs on more than one PHP node behind a load balancer. A shared network Redis reintroduces every question the socket answered for free: binding, authentication, TLS, firewall rules. Solve those deliberately rather than by pointing WP_REDIS_HOST at an internal IP and hoping. And if the slow pages are slow because of one unindexed query, no object cache fixes that. For the Redis configuration in more depth, the full object cache setup walkthrough picks up where this stops.

Running WordPress that earns real money deserves an operator — Stack Harbor runs that stack under Enterprise WordPress; book an infrastructure consult.