Using Redis with WordPress
On this page
There are a number of Redis plugins for WordPress, only some of which are compatible with Platform.sh. We’ve tested and recommend WP Redis and Redis Object Cache, both of which require a minimal amount of configuration.
To create a Redis service, add the following to your services configuration:
That creates a service named
rediscache with the type
redis, specifically version
Next open a connection to the new Redis service.
relationships section of your app configuration,
add the following:
The key (left side) is the name that’s exposed to the application in the
The value (right side) is the name of the service you specified in step 1 (
rediscache) and the endpoint (
If you named the service something different in step 1, change
rediscache to that.
Add the Redis extension for PHP in one of two ways:
- In your app configuration (for extension versions tied to the PHP version)
- Using a builder script (if you need more control over the extension version)
If you’re using Composer to build WordPress, install your chosen Redis plugin with a Composer command depending on the plugin:
Then commit the resulting changes to your
To enable the Redis cache to work with WordPress,
object-cache.php file needs to be copied from the plugin’s directory to the
Add the following line to the bottom of your
build hook in your app configuration,
adjusting the paths based on where your plugins are located:
It should now look something like:
bash .platform-scripts/install-redis.sh 6.0.12
# Copy manually-provided plugins into the plugins directory.
# This allows manually-provided and composer-provided plugins to coexist.
rsync -a plugins/* wordpress/wp-content/plugins/
if [ -f wordpress/wp-content/plugins/redis-cache/includes/object-cache.php ]; then
cp wordpress/wp-content/plugins/redis-cache/includes/object-cache.php wordpress/wp-content/object-cache.php
Each plugin requires slightly different configuration.
Place the code for your chosen plugin in the
somewhere before the final
require_once(ABSPATH . 'wp-settings.php'); line.
The following examples assume you are using the Config Reader library.
These sections set up the parameters the plugins look for to connect to the Redis server. If you used a different name for the relationship above, change it accordingly. This code has no impact when run on a local development environment.
Once you have committed the above changes and pushed, you need to activate the plugins.
Run this command in a SSH session in your environment:
redis-cli -h redis.internal info.
You should run it before you push all this new code to your repository.
This should give you a baseline of activity on your Redis installation. There should be very little memory allocated to the Redis cache.
After you push this code, you should run the command and notice that allocated memory starts jumping.
To verify the plugins are working, add a
redis command to the WP CLI tool.
While in a SSH session in your environment,
you can run
wp help redis to see the available commands your chosen plugin has added.