Series: WordPress Performance on DirectAdmin (Rocky Linux 9)
Phase 3: Database & Object Caching — Part 11 of 30
Redis vs Memcached for WordPress: Which One Should You Use?
Introduction
Object caching is critical for scaling WordPress, especially on DirectAdmin-managed servers running Rocky Linux 9. Redis and Memcached are the two most common solutions. This article compares both, focusing on implementation, performance, and maintainability within a DirectAdmin context. You’ll find concrete steps, safe defaults, and testing methods to help you choose and deploy the right cache backend for your workload.
Why Use Object Caching for WordPress?
WordPress relies heavily on MySQL queries for dynamic content generation. Object caching stores query results and PHP objects in memory, reducing database load and significantly improving response times for authenticated users and admin pages. DirectAdmin’s per-domain PHP-FPM pools and potential NGINX/Apache reverse proxy setups make cache backend selection and configuration especially relevant.
Overview of Redis and Memcached
- Memcached: Simple, in-memory key/value store. Extremely fast. No persistence. LRU eviction when memory is full.
- Redis: Advanced in-memory data structure store. Supports strings, hashes, lists, sets, and more. Optional disk persistence. More features, slightly higher resource use.
DirectAdmin and Rocky Linux 9 Considerations
- DirectAdmin typically manages PHP-FPM pools per domain. Object cache daemons must be available to all pools that need them.
- Default NGINX/Apache templates may not expose cache ports to the public internet, but always verify firewall rules.
- PHP modules for Redis and Memcached must be installed for every PHP version in use.
Installation Steps
1. Install the Server Daemon
- Redis:
sudo dnf install redis sudo systemctl enable --now redis sudo systemctl status redis - Memcached:
sudo dnf install memcached sudo systemctl enable --now memcached sudo systemctl status memcached
2. Secure and Configure the Cache Daemon
- By default, both services bind to
127.0.0.1. Confirm with:
sudo ss -ltnp | grep -E "6379|11211"
- Allow only local connections unless you have a multi-server architecture.
- For Redis, consider setting a password in
/etc/redis.confusingrequirepass. Restart Redis after changes.
3. PHP Extension Installation (per PHP version)
- DirectAdmin typically uses multiple PHP versions. For each version (e.g., PHP 8.1):
sudo dnf install php81-php-pecl-redis php81-php-pecl-memcached
- Restart the relevant PHP-FPM pool(s) after installation:
sudo systemctl restart php-fpm81-php
- Check that the extension is loaded:
/opt/alt/php81/usr/bin/php -m | grep -E "redis|memcached"
4. Firewall Configuration
- On Rocky Linux 9 with firewalld, confirm ports are not exposed externally:
sudo firewall-cmd --list-all
- Neither Redis (6379) nor Memcached (11211) should appear in
ports:unless intentionally configured for remote access.
DirectAdmin-Specific PHP-FPM/NGINX/Apache Integration
- Both Redis and Memcached are accessed via localhost, so no DirectAdmin NGINX/Apache template changes are required for local use.
- If you use cagefs or similar PHP isolation, ensure the cache socket/port is available inside the cage.
For advanced tuning or nonstandard setups (e.g., using UNIX sockets for Redis), you may need to update DirectAdmin’s custom PHP-FPM pool templates. Refer to earlier series posts for safe template editing procedures.
WordPress Plugin Selection and Configuration
Install a caching plugin compatible with both Redis and Memcached, such as object-cache.php drop-ins (Redis Object Cache or WP Memcached). Avoid running both Redis and Memcached simultaneously for the same site.
Enabling Object Cache via WP-CLI
cd /home/USER/domains/DOMAIN/public_html
wp plugin install redis-cache --activate
wp redis enable
wp redis status
For Memcached, the process is similar; check the documentation for drop-in installation and activation. Confirm the cache is operational:
wp cache type
Performance Testing and Validation
After enabling object caching, always validate with:
- WP-CLI object cache status (see above).
- Load testing: use
curl,wrk, ork6against key pages.wrk -t4 -c40 -d30s http://yourdomain.tld/ - Monitor logs for errors:
sudo tail -f /var/log/php-fpm/www-error.log sudo tail -f /var/log/redis/redis.log sudo tail -f /var/log/messages
Which to Choose? Redis vs Memcached for DirectAdmin WordPress
Memcached: Pros and Cons
- Pros: Lower memory overhead, simple, extremely fast for basic get/set operations, easy to configure.
- Cons: No persistence—data lost on restart. Fewer advanced features. No authentication by default.
Redis: Pros and Cons
- Pros: Supports persistence (optional), authentication, advanced data types, better at handling larger objects and more complex caching.
- Cons: Slightly higher memory use, more complex configuration, can be overkill for very basic sites.
Decision Table
| Scenario | Recommended Cache | Notes |
|---|---|---|
| Small sites, simple needs | Memcached | Minimal config, fast, low resource |
| Busy sites, e-commerce, multisite, or API-driven | Redis | Persistence, advanced features, security |
| Need for cache data after server reboot | Redis | Enable AOF or RDB persistence |
| Very constrained VPS (~512MB RAM) | Memcached | Lower baseline memory usage |
Recommended Defaults and Tuning
Redis
- Listen address:
127.0.0.1:6379 - Password: Set
requirepassin/etc/redis.conf - Persistence: Disable for pure object cache (set
save ""in/etc/redis.conf), enable if you want data durability. - Memory: Set
maxmemoryto 128–512MB for most WordPress sites. Usemaxmemory-policy allkeys-lru.
sudo sed -i "s/^# requirepass .*/requirepass YOURSTRONGPASSWORD/" /etc/redis.conf
sudo sed -i "s/^# maxmemory .*/maxmemory 256mb/" /etc/redis.conf
sudo sed -i "s/^# maxmemory-policy .*/maxmemory-policy allkeys-lru/" /etc/redis.conf
sudo systemctl restart redis
Memcached
- Listen address:
127.0.0.1:11211 - Memory: Edit
/etc/sysconfig/memcachedand adjust-m(e.g.,MEMCACHED_PARAMS="-m 256 -l 127.0.0.1"). - Restart to apply changes:
sudo systemctl restart memcached
Testing After Deployment
- Run
wp cache flushand load test to watch change in database query counts. - Monitor
toporhtopfor memory usage. - Check
redis-cli infoorecho stats | nc localhost 11211for hit/miss rates.
Key Takeaways
- Both Redis and Memcached offer major performance improvements over no object cache.
- Redis is more flexible and secure, while Memcached is lighter and simpler.
- For most modern WordPress sites on DirectAdmin/Rocky Linux 9, Redis is the better long-term choice, but Memcached remains viable for resource-constrained or legacy environments.
Note: This article offers general technical guidance. Validate all configurations in a safe environment before applying them to production.
Previous: How to Set Up Redis Object Cache for WordPress on DirectAdmin
Next: MariaDB Performance Tuning for WordPress on Rocky Linux

