Skip to content

Setting up Redis object cache for WordPress on cPanel

How to configure a Redis-backed WordPress object cache on a cPanel server — installation, wp-config integration, isolation between sites, and the typical pitfalls.

WordPress’s default object cache is in-memory and dies at the end of each PHP request. Every page load re-runs the same database queries for the same options, the same user meta, the same term lookups. A Redis-backed persistent object cache keeps that work across requests. On a moderately complex WordPress site, the impact is measured in 30-60% reduction of database load. On WooCommerce, more.

What’s happening

WordPress has an internal cache API (wp_cache_get, wp_cache_set). With no drop-in, it’s per-request memory. With a persistent backend (Redis, Memcached, LiteSpeed Memcached) and an object-cache.php drop-in, it persists across requests. Redis is the most common choice because it supports TLS, replication, and a richer command set than Memcached, and the WordPress drop-ins for Redis (Redis Object Cache by Till Krüss, Object Cache Pro) are mature.

How to verify

Confirm Redis is installed and running on the cPanel host:

which redis-cli
systemctl status redis 2>/dev/null
redis-cli ping
redis-cli info server | head

If Redis isn’t installed, the cPanel host operator needs to install it. On CentOS/AlmaLinux/RHEL hosts it’s dnf install redis. Make sure each cPanel user’s PHP has the redis extension or phpredis enabled — check with php -m | grep redis.

The fix

  1. Install the PHP redis extension for each PHP version you’re using:

    /scripts/phpextensionmgr install Redis

    In MultiPHP, the extension is usually exposed as php-pecl-redis or php-redis. Verify per-version with ea-php82 -m | grep redis.

  2. On a multi-tenant cPanel host, the key concern is isolation. By default Redis listens on 127.0.0.1:6379 with no authentication and all clients share the same keyspace. That’s wrong on a cPanel host where multiple accounts share Redis. Fix in /etc/redis.conf:

    • Set requirepass <strong-password> and distribute per-account, or
    • Use Unix sockets with per-account permissions (unixsocket /var/run/redis/redis.sock, unixsocketperm 770), and put each cPanel user’s PHP-FPM group in the socket’s group.
  3. Pick a database number per WordPress site so they don’t collide on key names. Redis supports databases 0-15 by default. Document the assignment in a per-server spreadsheet or runbook.

  4. Install the WordPress plugin (Redis Object Cache by Till Krüss). Configure in wp-config.php:

    define( 'WP_REDIS_HOST', '127.0.0.1' );
    define( 'WP_REDIS_PORT', 6379 );
    define( 'WP_REDIS_PASSWORD', 'strong-password' );
    define( 'WP_REDIS_DATABASE', 3 );
    define( 'WP_CACHE_KEY_SALT', 'example.com:' );
    define( 'WP_REDIS_DISABLED', false );

    WP_CACHE_KEY_SALT is the defensive belt — even if two sites end up sharing a database number, their keys won’t collide.

  5. Enable the drop-in from the plugin’s Settings page (Object Cache). It writes wp-content/object-cache.php. After enabling, the Settings page should show “Status: Connected.”

  6. Verify the cache is being used:

    wp redis status
    redis-cli -a 'strong-password' -n 3 dbsize

    wp redis status should report Connected with a positive hit ratio after a few page loads. dbsize should grow as the site is browsed.

  7. Tune maxmemory and maxmemory-policy in /etc/redis.conf. Start with maxmemory 256mb and maxmemory-policy allkeys-lru. On larger sites, increase maxmemory. The LRU policy ensures Redis evicts old keys instead of refusing writes when full.

  8. Monitor. Add Redis to whatever monitoring the cPanel host uses. Key metrics: used memory, evicted keys per minute, connected clients, ops per second.

For environments running Redis at scale across many WordPress sites, Stack Harbor handles the operational layer as part of managed cPanel operations.

Stack Harbor operates production WordPress at scale — see enterprise WordPress hosting for the managed model, or book a WordPress consult for a written read of your current shape.