Series: WordPress Performance on DirectAdmin (Rocky Linux 9)
Phase 3: Database & Object Caching — Part 9 of 30
Understanding WordPress Object Cache (Without the Myths)
WordPress object caching is a critical, often misunderstood layer for performance optimization, especially on DirectAdmin-managed Rocky Linux 9 servers. This article offers an engineering-focused examination of the object cache, dispels common misconceptions, and provides actionable steps for sysadmins to configure and validate object caching in a DirectAdmin environment.
What is WordPress Object Cache?
The WordPress object cache temporarily stores results of database queries and expensive operations in memory during a single request. By default, this cache is non-persistent—it is reset at the end of each PHP process. To achieve persistent object caching (across requests), an external backend such as Redis or Memcached is needed.
DirectAdmin Context: Why it Matters
- DirectAdmin creates separate PHP-FPM pools per domain/user. Object cache backends must be accessible by each pool.
- Configuration is typically per-site; be aware of multi-PHP and per-domain tuning requirements.
- Panel-based NGINX/Apache templates may require explicit configuration for socket access or firewall rules for TCP-based caches.
Common Myths About Object Caching
- Myth: Enabling any object cache plugin will always make WordPress faster. Reality: Ineffective or misconfigured backends can slow down your site, especially with local-only or file-based caches.
- Myth: Redis/Memcached are “set and forget.” Reality: Memory exhaustion, eviction policies, and backend crashes can cause failures or stale data. Monitoring is essential.
- Myth: Object cache replaces the need for a page cache. Reality: They complement each other; object cache speeds up backend processing, while page cache delivers full-page HTML to visitors.
Choosing an Object Cache Backend
- Redis: Most popular in modern WordPress, well-supported, persistent by default.
- Memcached: Simpler, can be faster for some workloads, but not persistent.
On Rocky Linux 9, both are available via dnf. Redis is generally recommended for new deployments due to its richer feature set and better plugin support.
Step-by-Step: Setting Up Redis Object Cache on DirectAdmin (Rocky Linux 9)
-
Install Redis server and PHP extension:
sudo dnf install redis php-pecl-redis- For multi-PHP setups, install the Redis extension for each PHP version used:
-
sudo dnf install php81-php-pecl-redis php82-php-pecl-redis
-
Enable and start Redis:
sudo systemctl enable --now redis -
Configure Redis for WordPress use:
- By default, Redis listens on
127.0.0.1:6379. This is usually sufficient for single-server DirectAdmin setups. - Review
/etc/redis.conf:- Set
supervised systemdfor systemd integration. - For shared hosting, consider authentication (
requirepassdirective).
- Set
- Restart Redis after changes:
sudo systemctl restart redis
- By default, Redis listens on
-
Verify PHP-FPM Redis extension is active:
php -m | grep redis- For alternate PHP versions:
-
/opt/alt/php81/usr/bin/php -m | grep redis
-
Install a persistent object cache plugin:
wp plugin install redis-cache --activate- Run as the correct user; see DirectAdmin’s user context or use
sudo -u USERas needed.
- Run as the correct user; see DirectAdmin’s user context or use
-
Enable object caching in WordPress:
wp redis enable- Check status:
-
wp redis status
Checklist: After Enabling Object Cache
- Verify Redis server is running:
sudo systemctl status redis - PHP-FPM pools have the Redis module loaded.
- Object cache plugin status is Connected via WP-CLI.
- Review
wp-config.phpfor custom Redis configuration (host, port, password). - Monitor Redis memory usage:
redis-cli info memory
Testing and Validating Object Cache Performance
-
Check cache hit rate:
wp redis info- Look for
keyspace_hitsandkeyspace_misses; increasing hits indicate effective caching.
- Look for
-
Benchmark with and without object cache:
- Disable object cache for baseline:
-
wp redis disable - Use
curlorwrkfor simple load testing: -
wrk -t4 -c32 -d30s http://yourdomain.example/
-
Compare PHP-FPM and Redis metrics:
- Monitor PHP-FPM status if enabled (
pm.status_pathin pool config). - Check Redis stats during load:
redis-cli monitor
- Monitor PHP-FPM status if enabled (
-
Review error logs:
- WordPress:
wp-content/debug.log(ifWP_DEBUG_LOGenabled) - PHP-FPM:
/var/log/php-fpm/error.logor per-pool logs - Redis:
/var/log/redis/redis.log
- WordPress:
Troubleshooting Checklist
- Plugin reports “Not connected”: Check Redis host/port and PHP extension.
- Frequent cache misses: Some plugins/themes are not cache-aware; review usage patterns.
- Out of memory errors: Adjust
maxmemoryandmaxmemory-policyin/etc/redis.conf(e.g.,maxmemory 256mb). - Permission issues: Ensure PHP-FPM pool user can access Redis socket/TCP port.
DirectAdmin-Specific Notes
- For PHP-FPM pools, check pool config (e.g.,
/usr/local/directadmin/data/users/USERNAME/php-fpm81.conf) if you need to adjust environment variables or limits for Redis. - NGINX/Apache templates rarely need changes unless you proxy Redis over a Unix socket or restrict loopback networking.
- Firewall: Redis should not be exposed externally. Confirm with:
sudo firewall-cmd --list-allsudo ss -ltnp | grep 6379
Recommended Defaults and Tuning Strategies
- Redis memory: Start with
256mbfor small sites,512mb–1gbfor larger ones. Adjust based on monitoring. - Eviction policy: Use
allkeys-lrufor general-purpose WordPress sites:maxmemory-policy allkeys-lru - Authentication: Set a strong password in
/etc/redis.conf:requirepass <your_strong_password> - Per-site tuning: For resource-heavy sites, consider a dedicated Redis instance or separate databases (see
databaseoption in Redis docs).
Rolling Back Object Cache
To safely disable persistent object cache, run:
wp redis disable
wp plugin deactivate redis-cache
Monitor site functionality and PHP error logs. No downtime is expected from disabling the plugin, but always test in staging if possible.
Key Takeaways
- Persistent object cache is a backend accelerator, not a frontend solution.
- Correct Redis/PHP-FPM integration is crucial on DirectAdmin-managed Rocky Linux 9.
- Monitor cache hit rates, memory usage, and logs regularly.
- Test all changes in a safe environment before rolling out to production.
Note: This article offers general technical guidance. Validate all configurations in a safe environment before applying them to production.
Previous: Why Your WordPress Site Is Slow Even With OPcache Enabled
Next: How to Set Up Redis Object Cache for WordPress on DirectAdmin

