Questions? Feedback? powered by Olark live chat software
Knowledgebase
Author Avatar

Install Redis Caching for Wordpress

Written by: on 22 May 2015 02:54 PM 22 May 2015 02:54 PM

This step by step method will will teach how to inatall redis caching for Wordpress. Follow to learn fast.

Our users have reported approximately 30% increase in page loading speed by installing the Redis Caching module for Wordpress.

This can easily be installed on cPanel servers as well as any other CentOS or Ubuntu webserver.

Installing Redis

To install Redis as daemon on a CentOS/RHEL/cPanel server, do the following steps.

Go to http://redis.io/download and determine the latest stable version (3.0.1 at the time of writing) - replace 3.0.1 in the instructions below with the latest version

SSH into your server

cd /usr/local/
wget http://download.redis.io/releases/redis-3.0.1.tar.gz
tar -xvzf redis-3.0.1.tar.gz
cd redis-3.0.1
make
cp src/redis-server /usr/local/bin
cp src/redis-cli /usr/local/bin
mkdir -p /etc/redis
mkdir -p /var/redis
cp redis.conf /etc/redis/redis.conf

nano /etc/redis/redis.conf
Find and set the following values:

daemonize yes
port 6379
bind 127.0.0.1
dir  /var/redis/
logfile  /var/log/redis.log
pidfile  /var/run/redis.pid

Save the file (CTRL O)

Exit (CTRL X)

nano /etc/init.d/redis (reference https://gist.github.com/paulrosania/257849)
Paste in the following

#!/bin/sh
#
# redis - this script starts and stops the redis-server daemon
#
# chkconfig:   - 85 15 
# description:  Redis is a persistent key-value database
# processname: redis-server
# config:      /etc/redis/redis.conf
# config:      /etc/sysconfig/redis
# pidfile:     /var/run/redis.pid
 
# Source function library.
. /etc/rc.d/init.d/functions
 
# Source networking configuration.
. /etc/sysconfig/network
 
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
 
redis="/usr/local/bin/redis-server"
prog=$(basename $redis)
 
REDIS_CONF_FILE="/etc/redis/redis.conf"
 
[ -f /etc/sysconfig/redis ] && . /etc/sysconfig/redis
 
lockfile=/var/lock/subsys/redis
 
start() {
    [ -x $redis ] || exit 5
    [ -f $REDIS_CONF_FILE ] || exit 6
    echo -n $"Starting $prog: "
    daemon $redis $REDIS_CONF_FILE
    retval=$?
    echo
    [ $retval -eq 0 ] && touch $lockfile
    return $retval
}
 
stop() {
    echo -n $"Stopping $prog: "
    killproc $prog -QUIT
    retval=$?
    echo
    [ $retval -eq 0 ] && rm -f $lockfile
    return $retval
}
 
restart() {
    stop
    start
}
 
reload() {
    echo -n $"Reloading $prog: "
    killproc $redis -HUP
    RETVAL=$?
    echo
}
 
force_reload() {
    restart
}
 
rh_status() {
    status $prog
}
 
rh_status_q() {
    rh_status >/dev/null 2>&1
}
 
case "$1" in
    start)
        rh_status_q && exit 0
        $1
        ;;
    stop)
        rh_status_q || exit 0
        $1
        ;;
    restart|configtest)
        $1
        ;;
    reload)
        rh_status_q || exit 7
        $1
        ;;
    force-reload)
        force_reload
        ;;
    status)
        rh_status
        ;;
    condrestart|try-restart)
        rh_status_q || exit 0
	    ;;
    *)
        echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
        exit 2
esac

Save the file (CTRL O)

Exit (CTRL X)

chmod 755 /etc/init.d/redis

Now make sure the daemon will start after server reboot.

chkconfig --add redis
chkconfig redis on

service redis start

To make sure redis is working, run command "redis-cli ping" from commandline. If you get result "PONG", that shows redis is working.

Now install redis PHP extension, using following command.

pecl install redis

nano /usr/local/lib/php.ini
Find the extension section and add a new line

extension=redis.so;

Save the file (CTRL O)

Exit (CTRL X)

service httpd restart

 

Installing the Redis WordPress Plugin

1. Go to https://wordpress.org/plugins/redis-cache/

2. Download the plugin and install it to your wordpress site.

3. In WordPress go to the Redis Cache Plugin page and click the green 'Enable Redis Object Cache' button. Redis may list as not installed prior to clicking that button, but if you have done the above correctly it will change the status to 'Connected'.

(0 vote(s))
Helpful
Not helpful