Speed up your WordPress site width Redis cache on Ubuntu and Centos server

Redis can be compiled and used on Linux, OSX, OpenBSD, NetBSD, FreeBSD. We support big endian and little endian architectures.
It may compile on Solaris derived systems (for instance SmartOS) but our
support for this platform is “best effort” and Redis is not guaranteed to work as well as in Linux, OSX, and *BSD there.
This is the caching method used over at Gatsby and any WordPress based client sites I maintain. As the cache is in-memory, it handles surges of traffic very well.
This tutorial assumes you already have WordPress set up and ready to roll.

Install Redis on Ubuntu 12.04/13.04/13.10

First edit /etc/apt/sources.list file:

#sudo nano /etc/apt/sources.list

and add add these two lines:

deb http://packages.dotdeb.org wheezy all
deb-src http://packages.dotdeb.org wheezy all
# sudo apt-get update

Install Redis:

# sudo apt-get install redis -y

Install Redis on RHEL/CentOS 5.x/6.x

First add Remi repository.
Now, install redis using yum command:

# yum nistall redis -y

Run redis

# /etc/init.d/redis start


# /etc/init.d/redis-server start

Make WordPress Use Redis

Here’s the last step. We’re going to need a couple of files to make WordPress interact with Redis.
The idea is that we want to use a new index.php, so that every single valid request hits Redis before asking WordPress to regenerate the page.
To do that, we’ll have to move the original index.php

# mv index.php backup_index.php

You’ll then need to grab predis.php so PHP can interact with Redis

wget http://uploads.staticjw.com/ji/jim/predis.php

Finally, grab the new index.php

wget http://pastie.org/pastes/7953263/text -O index.php

If all goes well, load up your WordPress site and pages should appear. If not, you’ve probably done something wrong.

Leave a Reply

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


This site uses Akismet to reduce spam. Learn how your comment data is processed.

Back to top button