Using Redis with WordPress on Ubuntu

Share on facebook
Share on twitter
Share on reddit
Share on linkedin

Redis is “an open source (BSD licensed), in-memory data structure store, used as a database, cache and message broker. It supports data structures such as strings, hashes, lists, sets, sorted sets with range queries, bitmaps, hyperloglogs, geospatial indexes with radius queries and streams.”

Translation? It makes websites run faster. And we’re all about “faster,” so let’s talk about how to put Redis to use with your WordPress website.

Installing on Ubuntu

Because it’s in the Ubuntu repository, you can install Redis on Ubuntu 18.04 with:

sudo apt install redis-server libphp-predis

Next, we’ll want to edit the configuration file and make a few small changes.

sudo nano /etc/redis/redis.conf

Inside this file, make the following changes:

  • Replace “supervised no” with “supervised systemd”;
  • Find “# bind ::1” and uncomment it (by removing the “#”);
  • Find “# requirepass foobared”, uncomment it, and replace “foobared” with a secure password of your choosing.

Save your changes and restart Redis with:

sudo systemctl restart redis

Adding Redis to WordPress

Our preference for Redis plugins is “Redis Object Cache” by Till Krüss. At the time of this writing, it has over 40K active installations and a 4.5 average rating. Install and activate the plugin. In Settings > Redis, you should see this:

Don’t click that “Enable Object Cache” button yet, though; we still need to make one more change. Edit your WordPress site’s wp-config.php file and add the following:

define('WP_REDIS_CLIENT', 'predis');
define('WP_REDIS_PASSWORD', 'MySuperSecurePassword');

(The password is the one you put in /etc/redis/redis.conf.)

After saving your wp-config.php, you can go back and click “Enable Object Cache”. You should see this:

The one small difference from your screenshot and ours is that yours should show “0” in the “Databases” column. We run a lot of websites, some of which share Redis installations, so we use the WP_REDIS_DATABASE option to separate logical databases.

There are a number of other available options for the Redis Object Cache plugin, all of which are documented on

If you have any questions or problems, please hit us up in the comments below.

More to explore

Photo by Artem Sapegin on Unsplash

2 Must-Have Tools for WordPress Development

There are some exceptional tools that can be used for WordPress development that make the process way easier than it would be otherwise. I didn’t know about some of these early on in my WordPress development days, so for those of you who might not be familiar with them, I’d like to share.

Photo by Caspar Camille Rubin on Unsplash

Getting WP Post and Postmeta in Single Rows

WordPress uses wp_posts to store post, page, and Custom Post Type (CPT) data the wp_postmeta table for Custom Metabox data. To retrieve this data you have to read for the post plus multiple linked postmeta rows. In this post, we conquer postmeta with subqueries.

Nasa on Unsplash

Building an API Endpoint with Amp (PHP)

API endpoints in web apps are pretty typical these days, but there may be reasons to provide data outside of the context of an application. In this post, we’ll explore how to make a stand-alone API endpoint using PHP and Amp.

Leave a Comment

Your email address will not be published. Required fields are marked *