WordPress dashboard showing Redis object cache setup on DirectAdmin

How to Set Up Redis Object Cache for WordPress on DirectAdmin

, , , , ,

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 redis should 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.

  1. Edit /etc/redis.conf:
sudo vi /etc/redis.conf
  • Set bind 127.0.0.1 (comment out or remove other bind lines).
  • Set supervised systemd (improves systemd integration).
  • Optional but recommended: Set a requirepass for extra security.
  1. 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).

  1. 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.

  1. 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_PREFIX in wp-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

  1. Check plugin status via WP-CLI:
wp redis status
  1. Run a WordPress cache flush to verify:
wp cache flush
  1. Inspect Redis activity:
redis-cli monitor
  1. Benchmark with curl or wrk:
wrk -t4 -c40 -d30s http://yourdomain.com/
# or
curl -I http://yourdomain.com/
  1. 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_PREFIX or separate Redis databases if strict isolation is needed.

Step 10: Troubleshooting Checklist

  • Plugin not connecting? Check redis-server status and php_redis extension via php -m.
  • Authentication errors? Ensure WP_REDIS_PASSWORD matches requirepass in redis.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.ini loads the extension for each version.

Summary Checklist

  1. Install and secure Redis (dnf, /etc/redis.conf).
  2. Enable php_redis via DirectAdmin custombuild.
  3. Install and activate Redis Object Cache plugin with WP-CLI.
  4. Configure password and prefix as needed.
  5. Test with wp redis status and real HTTP requests.
  6. 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?

Smart reads for curious minds

We don’t spam! Read more in our privacy policy