Using Redis with WordPress on Ubuntu

Share on facebook
Facebook
Share on twitter
Twitter
Share on reddit
Reddit
Share on linkedin
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 127.0.0.1 ::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 WordPress.org.

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

More to explore

Photo by Kyle Broad on Unsplash

“I Know You”

I’ve a few recordings that have survived the changes in technology and the natural degradation of formats such as tape. This song,

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.

Leave a Comment

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