Redis Caching WordPresss on CentOS 7

Caching WordPress with Nginx and Redis is quite simple if you are using Ubuntu, as you can just follow this tutorial, but what if you want to use CentOS, or even better, want to automate the setup using Ansible?

First of all, you will need to install the EPEL and REMI repositories and of course, Redis.

You will need to have the following Nginx modules installed. srcache-nginx-module, HttpRedisModule, redis2-nginx-module, set-misc-nginx-module Fortunately, there is a third party Nginx distribution called OpenResty that comes with all of the required modules. You can either build it from source or install it from their repository. Even better, you can install it using Ansible.

If you wish to install it from source using Ansible, here are the tasks.

The template used for generating the build script.

Or if you wish to use a pre-built binary from a repository, you can use these tasks.

Now, of course, you will need to configure OpenResty and Systemd, so here are example configuration files that you can modify to your liking.

Systemd service file

Nginx.conf
Here is a link to the nginx.conf I use for this website.

default.conf
Note: If you wish to use a vhost, you can modify this and use it as a sitename.conf
Here is a link to the default.conf am using for this website. Yes, CloudFlare accepts self-signed connections from servers. I know it is not a pretty solution, but Let’s Encrypt does not work behind reverse proxy servers or in firewalled local development environments.

Now, you will have to install the php71-php-pecl-redis package and configure the connection to the Redis server so it can cache PHP sessions.
As a reference, here are the tasks I use to install and configure PHP for this website.

Now, if everything works, you will be able to ssh into the server and run redis-cli and then monitor and see this whenever a page is requested.

redis-cli monitor output
redis-cli monitor output

Posted

in

by

Tags: