DEV Community

Cover image for How to use Redis with WordPress (docker-compose)
Alexandre Plennevaux
Alexandre Plennevaux

Posted on


How to use Redis with WordPress (docker-compose)

I'm putting this here because it took me a long while to figure this out.

I wanted to improve WordPress's performance by using Redis object caching. My environment is defined in a docker compose.

version: '3.6'
      image: 'redis:alpine'
        - '6379:6379'
      restart: always
        - '6379'

      image: 'wordpress:latest'
Enter fullscreen mode Exit fullscreen mode

There is a handy WordPress plugin for that, but of course, it needs redis to be installed and configured properly. That's the part I struggled with as it could not connect to my redis container.

Normally, Redis should work out-of-the-box with WordPress as long as it is accessible via localhost:6379.

The thing is, in a docker setup the redis instance is accessible via its container name.

So in the above example, in order for WordPress to find it, you need to modify the constant WP_REDIS_HOST to "redis" in your wp-config.php file.

define('WP_REDIS_HOST', 'redis');
define('WP_REDIS_PORT', '6379');
Enter fullscreen mode Exit fullscreen mode

Additional constants are available. More information is available here.

That's it, really. I hope this helps someone.

Oldest comments (2)

uebmaster profile image

i did it and works with default theme, but when i try to install hub theme ( i got a message like the link has expired.

but if i use a solution like, which also works under docker, i can install the theme without problem, what am i doing wrong?

trainingcity profile image
John Downing

Looks like this recipe may longer work. I am running into an issues today with the latest plugin release. FYI: