Use Redis with WordPress on Debian Wheezy

By | 2014/10/02

Redis works great with WordPress as a cache in place of memcached. Here is how to setup Redis with a WordPress install!


This example is based on Debian Wheezy.

1. Install Redis and some needed php packages:

$ sudo apt-get install redis-server php5-dev php-pear

Because Debian Wheezy doesn’t offer php5-redis, install your own php redis extension:

$ sudo pecl install redis

2. Next, create the following file:

$ sudo vim /etc/php5/mods-available/redis.ini

Put in the following and save:

extension=redis.so

3. Next, create a symlink to enable this php extension.

$ sudo ln -s /etc/php5/mods-available/redis.ini /etc/php5/conf.d/


WordPress Config

1. Download the file object-cache.php from here and place in /wp-content of your WordPress install.


2. Next, edit your wp-config.php and add a cache key salt with the name of your site (or any string you would like):

define('WP_CACHE_KEY_SALT', 'scottlinux.com');

define('WP_CACHE', true);


Redis as a Cache settings

You may wish to review the info here on using Redis as a cache (bottom of page):
http://redis.io/topics/config

This server has the following settings in /etc/redis/redis.conf to make Redis work like memcached:

maxmemory 256mb
maxmemory-policy allkeys-lru


3. Finally, restart redis-service and restart php5-fpm or apache2 if you are using apache. Done!


To monitor redis, use the redis-cli command like so:

$ redis-cli monitor

You will see redis requests fly by:

$ redis-cli monitor
OK
1412273195.815838 "monitor"
1412273198.428472 "EXISTS" "scottlinux.comwp_:default:is_blog_installed"
1412273198.428650 "GET" "scottlinux.comwp_:default:is_blog_installed"
1412273198.432252 "EXISTS" "scottlinux.comwp_:options:notoptions"
1412273198.432443 "GET" "scottlinux.comwp_:options:notoptions"
1412273198.432626 "EXISTS" "scottlinux.comwp_:options:alloptions"
1412273198.432799 "GET" "scottlinux.comwp_:options:alloptions"
1412273198.433572 "EXISTS" "scottlinux.comwp_site-options:0:notoptions"
1412273198.433729 "EXISTS" "scottlinux.comwp_:options:notoptions"
1412273198.433876 "GET" "scottlinux.comwp_:options:notoptions"
1412273198.434018 "EXISTS" "scottlinux.comwp_:options:alloptions"
1412273198.434161 "GET" "scottlinux.comwp_:options:alloptions"
1412273198.434745 "EXISTS" "scottlinux.comwp_:options:notoptions"
1412273198.434921 "GET" "scottlinux.comwp_:options:notoptions"
1412273198.435058 "EXISTS" "scottlinux.comwp_:options:alloptions"
1412273198.435193 "GET" "scottlinux.comwp_:options:alloptions"
1412273198.435737 "EXISTS" "scottlinux.comwp_:options:notoptions"
1412273198.435885 "GET" "scottlinux.comwp_:options:notoptions"
1412273198.436022 "EXISTS" "scottlinux.comwp_:options:alloptions"
1412273198.436157 "GET" "scottlinux.comwp_:options:alloptions"
1412273198.438298 "EXISTS" "scottlinux.comwp_:options:notoptions"
1412273198.438418 "GET" "scottlinux.comwp_:options:notoptions"
1412273198.438598 "EXISTS" "scottlinux.comwp_:options:alloptions"
1412273198.438700 "GET" "scottlinux.comwp_:options:alloptions"
1412273198.439449 "EXISTS" "scottlinux.comwp_:options:notoptions"
1412273198.439560 "GET" "scottlinux.comwp_:options:notoptions"
1412273198.439746 "EXISTS" "scottlinux.comwp_:options:alloptions"
1412273198.439844 "GET" "scottlinux.comwp_:options:alloptions"
1412273198.440764 "EXISTS" "scottlinux.comwp_:options:notoptions"
1412273198.440868 "GET" "scottlinux.comwp_:options:notoptions"
1412273198.441035 "EXISTS" "scottlinux.comwp_:options:alloptions"
1412273198.441149 "GET" "scottlinux.comwp_:options:alloptions"
1412273198.441813 "EXISTS" "scottlinux.comwp_:options:notoptions"
1412273198.441913 "GET" "scottlinux.comwp_:options:notoptions"
1412273198.442023 "EXISTS" "scottlinux.comwp_:options:alloptions"
1412273198.442121 "GET" "scottlinux.comwp_:options:alloptions"
1412273198.442652 "EXISTS" "scottlinux.comwp_:options:notoptions"
1412273198.442773 "GET" "scottlinux.comwp_:options:notoptions"
1412273198.442874 "EXISTS" "scottlinux.comwp_:options:alloptions"
1412273198.442974 "GET" "scottlinux.comwp_:options:alloptions"


To benchmark redis, there is a built-in benchmark utility:

$ redis-benchmark -c 10 -n 100000 -q
PING_INLINE: 38505.97 requests per second
PING_BULK: 40048.06 requests per second
SET: 38714.67 requests per second
GET: 39478.88 requests per second
INCR: 38037.28 requests per second
LPUSH: 38431.98 requests per second
LPOP: 38759.69 requests per second
SADD: 38476.34 requests per second
SPOP: 39215.69 requests per second
LPUSH (needed to benchmark LRANGE): 39215.69 requests per second
LRANGE_100 (first 100 elements): 27442.37 requests per second
LRANGE_300 (first 300 elements): 12938.28 requests per second
LRANGE_500 (first 450 elements): 9422.41 requests per second
LRANGE_600 (first 600 elements): 7680.49 requests per second
MSET (10 keys): 32051.28 requests per second

Optional!

For Debian Wheezy, a newer verson of redis is available in Wheezy backports:

$ sudo apt-get -t wheezy-backports install redis-server


2 thoughts on “Use Redis with WordPress on Debian Wheezy

  1. Markus

    Using backports, you just have to enter the following line in /etc/apt/sources.list:

    deb http://http.debian.net/debian wheezy-backports main

    After this, do an “apt-get update”.

    Now you can install: “apt-get install redis-server php5-redis”

    This way should be easier 😉

    Reply
    1. Scott Miller Post author

      Thanks! php5-redis was not available in backports at the original time of this post.

      Reply

Leave a Reply

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

Notify me of followup comments via e-mail. You can also subscribe without commenting.