Step 5: Configure Wordpress to use Redis

We know that our Redis Docker container is working. Now, let’s configure Wordpress to use our new service.

  1. Log into Wordpress at

  2. Add the Redis Object Cache plugin

    1. Plugins -> Add New -> Search for Redis Object Cache

    2. Install and then activate it

  3. Go to the plugin configuration panel

    1. Settings -> Redis

  4. Click Enable Object Cache

  5. Click Show Diagnostics

You will notice that the status reads Not Connected. Clicking Show Diagnostics will show additional details. You will also notice that the host is However, our Redis server is running on a different host, not on the localhost ( From the perspective of Wordpress, localhost is container wordpressdocker_wordpress_1. Redis is running on container wordpressdocker_redis_1.

Docker knows about this container because we included it in the depends_on property. So, we only need to set the server address to redis. Docker will take care of the rest of the work.

Connect WP to Redis

The Redis plugin help document page provides the information on variables that we can use to configure Redis to work without Docker container.

  • WP_REDIS_HOST: Defines a host other than

  • WP_CACHE_KEY_SALT: Separates the cache keys of Wordpress from other services that might use the same Redis instance. It guarantees uniqueness.

  1. Add these two variables to your wp-config.php file. You can change the WP_CACHE_KEY_SALT to something unique.

    define('WP_REDIS_HOST', 'redis');
    define('WP_CACHE_KEY_SALT', 'wp-docker-5DknvYepdjyJMo8gDqrLhrpAJUQ');

    We can modify wp-config.php easily because it is part of the Wordpress volume data. Nifty!

    nano wordpress/wp-config.php
    File contents of wp-config.php
    define('WP_REDIS_HOST', 'redis');
    define('WP_CACHE_KEY_SALT', 'wp-docker-5DknvYepdjyJMo8gDqrLhrpAJUQ');
    // ** MySQL settings - You can get this info from your web host ** //
    /** The name of the database for WordPress */
    define('DB_NAME', 'wordpress');
  2. Refresh the webpage. The status should have updated.

    Overview Output
    Status:    Connected
    Client:    Predis (v1.1.1)
    Key Prefix:    wp-docker-5DknvYepdjyJMo8gDqrLhrpAJUQ
  3. You can see the cached information in the Diagnostics frame.

    Diagnostics Output
    Status: Connected
    Client: Predis (v1.1.1)
    Drop-in: Valid
    Ping: PONG
    Redis Extension: Not Found
    Predis Client: 1.1.1
    PHP Version: 7.2.16
    Multisite: No
    Global Prefix: "wp_"
    Blog Prefix: "wp_"
    WP_REDIS_HOST: "redis"
    WP_CACHE_KEY_SALT: "wp-docker-5DknvYepdjyJMo8gDqrLhrpAJUQ"
    Global Groups: {"0":"blog-details","1":"blog-id-cache","2":"blog-lookup","3":"global-posts","4":"networks","5":"rss","6":"sites","7":"site-details","8":"site-lookup","9":"site-options","10":"site-transient","11":"users","12":"useremail","13":"userlogins","14":"usermeta","15":"user_meta","16":"userslugs","33":"blog_meta"}
    Ignored Groups: ["counts","plugins","themes"]
     - Redis Object Cache Drop-In v1.4.1 by Till Krüss
     - Akismet Anti-Spam v4.1.1 by Automattic (Inactive)
     - Hello Dolly v1.7.1 by Matt Mullenweg (Inactive)
     - Redis Object Cache v1.4.1 by Till Krüss (Active)


  1. Do you need to troubleshoot this further? Open a shell connection to the Wordpress docker container.

    docker exec -it wordpressdocker_wordpress_1 /bin/sh
  2. Add some essential tools

    apt update && apt install -y redis-tools iputils-ping
    root@vps298933:~/wordpress-docker# docker exec -it wordpressdocker_wordpress_1 /bin/sh
    # apt update && apt install -y redis-tools iputils-ping
    Get:1 stretch/updates InRelease [94.3 kB]
    Get:2 buster/updates InRelease [38.3 kB]
    Get:4 stretch/updates/main amd64 Packages [481 kB]
    Ign:3 stretch InRelease
    Get:5 stretch-updates InRelease [91.0 kB]
    Get:6 buster InRelease [158 kB]
    Get:7 buster-updates InRelease [46.8 kB]
    Get:8 stretch-updates/main amd64 Packages [11.1 kB]
    Get:9 stretch Release [118 kB]
    Get:10 buster/main amd64 Packages [7887 kB]
    Get:11 stretch Release.gpg [2434 B]
    Get:12 stretch/main amd64 Packages [7084 kB]
    Fetched 16.0 MB in 5s (3165 kB/s)
    Reading package lists... Done
    Building dependency tree
    Reading state information... Done
    All packages are up to date.
    Reading package lists... Done
    Building dependency tree
    Reading state information... Done
    The following additional packages will be installed:
      libcap2 libcap2-bin libjemalloc1 libpam-cap
    Suggested packages:
    The following NEW packages will be installed:
      iputils-ping libcap2 libcap2-bin libjemalloc1 libpam-cap redis-tools
    0 upgraded, 6 newly installed, 0 to remove and 0 not upgraded.
    Need to get 667 kB of archives.
    After this operation, 1863 kB of additional disk space will be used.
  3. Test the connection to the Redis server.


    We have to specify the host using the -h switch because Redis is running on a different host called redis.

    1. Ping the redis server using ping to test the network connection.

    2. Ping redis using redis-cli to test the server functionality

    3. View server info using redis-cli

    ping redis                       #Checks the network connection
    redis-cli -h redis ping          #Checks server response
    redis-cli -h redis info server   #View the server info
    # ping redis
    PING redis ( 56(84) bytes of data.
    64 bytes from wordpressdocker_redis_1.wordpressdocker_default ( icmp_seq=1 ttl=64 time=0.211 ms
    64 bytes from wordpressdocker_redis_1.wordpressdocker_default ( icmp_seq=2 ttl=64 time=0.100 ms
    --- redis ping statistics ---
    2 packets transmitted, 2 received, 0% packet loss, time 1001ms
    rtt min/avg/max/mdev = 0.100/0.155/0.211/0.056 ms
    # redis-cli -h redis ping
    # redis-cli -h redis info server
    # Server
    os:Linux 4.15.0-46-generic x86_64
  4. If these commands are successful, then the problem is in Wordpress.

  5. Type exit to leave the SSH session.

  6. Check the wp-config.php file.