Series: WordPress Performance on DirectAdmin (Rocky Linux 9)
Phase 3: Database & Object Caching — Part 10 of 30
How to Set Up Redis Object Cache for WordPress on DirectAdmin
Object caching is a crucial performance lever for WordPress, particularly on busy sites or those with dynamic content. Redis is a popular, robust in-memory data store that integrates well with WordPress for object caching. On DirectAdmin-managed Rocky Linux 9 servers, setting up Redis requires careful attention to service configuration, PHP-FPM pool integration, and plugin activation. This guide provides a step-by-step process, with DirectAdmin-specific notes and safe-by-default commands suitable for sysadmins.
Prerequisites
- DirectAdmin running on Rocky Linux 9 (EL9)
- Root or sudo access
- One or more WordPress installations managed via DirectAdmin
- PHP-FPM configured (default for DirectAdmin on EL9)
Step 1: Install Redis Server
Redis is available in EPEL for EL9. Install and enable the service:
sudo dnf install epel-release -y
sudo dnf install redis -y
sudo systemctl enable --now redis
sudo systemctl status redis
- Check:
systemctl status redisshould show active (running).
Step 2: Secure and Configure Redis
For single-server setups (WordPress and Redis on the same host), listen on 127.0.0.1 only. For multi-server, see later notes.
- Edit
/etc/redis.conf:
sudo vi /etc/redis.conf
- Set
bind 127.0.0.1(comment out or remove otherbindlines). - Set
supervised systemd(improves systemd integration). - Optional but recommended: Set a
requirepassfor extra security.
- Restart Redis to apply changes:
sudo systemctl restart redis
Downtime warning: Restarting Redis disconnects all clients. If other apps depend on Redis, schedule with care.
Step 3: Allow PHP-FPM to Use Redis
WordPress (PHP-FPM) must connect to Redis via 127.0.0.1:6379. No firewall changes are needed for local-only access. Verify with:
sudo ss -ltnp | grep 6379
If Redis is to be accessed from other hosts (rare for DirectAdmin), update bind, firewall, and requirepass accordingly. This guide assumes local access only.
Step 4: Install PHP Redis Extension
DirectAdmin uses custombuild for PHP extensions. For all PHP versions managed by DirectAdmin, run:
cd /usr/local/directadmin/custombuild
sudo ./build update
sudo ./build set php_redis yes
sudo ./build php_redis
- Check: Reload PHP-FPM pools to load the extension:
sudo systemctl reload php-fpm
- For multi-PHP setups, repeat reload for each version:
sudo systemctl reload php81-php-fpm
sudo systemctl reload php82-php-fpm
# ...etc, as applicable
- Verify loaded extension for each PHP version:
php -m | grep redis
# Or for alternate versions:
php81 -m | grep redis
php82 -m | grep redis
Step 5: Install and Configure WordPress Redis Object Cache Plugin
Recommended: Redis Object Cache plugin (official, maintained, CLI-friendly).
- Install the plugin via WP-CLI (run as the site user):
cd /home/USERNAME/domains/DOMAIN/public_html
wp plugin install redis-cache --activate
Replace USERNAME and DOMAIN as appropriate for your setup.
- Enable object caching:
wp redis enable
- Check status:
wp redis status
- If Redis requires a password (from your earlier
requirepass), configure plugin via:
wp config set WP_REDIS_PASSWORD 'your_redis_password' --type=constant
Per-Site Configuration
- If you run multiple WordPress sites, each uses a unique cache key prefix by default. To override, set
WP_REDIS_PREFIXinwp-config.php:
define('WP_REDIS_PREFIX', 'site1_');
Step 6: Tune Redis for DirectAdmin Workloads
Defaults are suitable for most small–medium sites. For busy or multi-site servers, consider:
- maxmemory: Limit memory usage to avoid swapping. Example (in
/etc/redis.conf):
maxmemory 256mb
maxmemory-policy allkeys-lru
- Restart Redis after config changes.
- Monitor usage:
redis-cli info memory
Step 7: Test Object Caching
- Check plugin status via WP-CLI:
wp redis status
- Run a WordPress cache flush to verify:
wp cache flush
- Inspect Redis activity:
redis-cli monitor
- Benchmark with
curlorwrk:
wrk -t4 -c40 -d30s http://yourdomain.com/
# or
curl -I http://yourdomain.com/
- Tail PHP-FPM and Redis logs for errors:
sudo tail -f /var/log/php-fpm/www-error.log
sudo journalctl -u redis -f
Step 8: (Optional) DirectAdmin NGINX/Apache Template Adjustments
No changes to NGINX or Apache proxy templates are needed for local Redis object cache. If you use Redis for full-page caching or as a session handler, update DirectAdmin’s templates accordingly. For object caching, PHP/WordPress integration is sufficient.
Step 9: Monitoring and Maintenance
- Monitor Redis memory and keyspace usage periodically:
redis-cli info stats
redis-cli info memory
redis-cli info keyspace
- Automate Redis restarts if memory leaks or crashes occur (systemd handles basic restarts by default).
- For multi-user DirectAdmin servers, ensure each user/site uses a unique
WP_REDIS_PREFIXor separate Redis databases if strict isolation is needed.
Step 10: Troubleshooting Checklist
- Plugin not connecting? Check
redis-serverstatus andphp_redisextension viaphp -m. - Authentication errors? Ensure
WP_REDIS_PASSWORDmatchesrequirepassinredis.conf. - Performance issues? Check Redis memory limit and eviction policy.
- Conflicts with other cache plugins? Disable any page cache plugins when testing object cache.
- For multi-PHP, ensure the correct
php.iniloads the extension for each version.
Summary Checklist
- Install and secure Redis (
dnf,/etc/redis.conf). - Enable
php_redisvia DirectAdmin custombuild. - Install and activate Redis Object Cache plugin with WP-CLI.
- Configure password and prefix as needed.
- Test with
wp redis statusand real HTTP requests. - Monitor logs and Redis stats for ongoing health.
Note: This article offers general technical guidance. Validate all configurations in a safe environment before applying them to production.
Previous: Understanding WordPress Object Cache (Without the Myths)
Next: Redis vs Memcached for WordPress: Which One Should You Use?

