Redis Support Comes to Trellis
Ben Word
on
WordPress sites can benefit significantly from object caching, which stores database query results in memory to reduce server load and improve page response times. Starting with Trellis v1.26.0, we’ve added built-in support for Redis object caching to make it easier than ever to boost your site’s performance.
What’s new
The latest Trellis release introduces comprehensive object cache support that works seamlessly with your existing WordPress sites. Here’s what we’ve added:
Redis Support: A new Redis role that installs and configures Redis server with sensible defaults optimized for WordPress object caching. The configuration includes memory management, persistence options, and security settings tailored for production use.
Environment Variable Integration: Automatic configuration of WordPress environment variables (WP_REDIS_HOST
, WP_REDIS_PORT
, etc.) based on your site configuration, eliminating manual setup.
Conditional Installation: Redis and Memcached are only installed when actually needed by your sites.
Redis Configuration
Enabling Redis object caching is straightforward. In your wordpress_sites.yml
, add an object_cache
section to any site:
wordpress_sites:
example.com:
# ... existing configuration
object_cache:
enabled: true
provider: redis
database: 0
Trellis handles the rest, including:
- Installing Redis server and PHP extension
- Configuring Redis with optimized settings
- Setting up environment variables for your WordPress site
- Managing cache prefixes to avoid conflicts between sites
Separate from FastCGI Cache
One important distinction: object caching is separate from FastCGI caching (which caches full page HTML). The existing cache.enabled
option continues to control FastCGI caching, while the new object_cache.enabled
option controls Redis/Memcached object caching. You can use both together for maximum performance benefits.
Production-ready defaults
The Redis configuration comes with production-ready defaults including:
- Memory limits and eviction policies
- Persistence configuration for data durability
- Security settings with disabled dangerous commands
- Optimized data structure settings
For advanced users, the configuration is fully customizable through Ansible variables.
Getting started
To start using object caching:
- Update to Trellis v1.26.0
- Add
object_cache
configuration to your sites - Re-provision your servers with
trellis provision
- Install a WordPress object cache plugin like Redis Object Cache
For complete setup instructions and configuration options, check out our Redis documentation.
Whether you’re running a high-traffic WordPress site or just want to optimize performance, object caching support in Trellis makes it easier to implement this powerful optimization technique.