How to Install Redis Object Caching on WordPress

Caching allows us to store data in RAM so that any future request for that data can be served faster, without any needing to query the database or process any PHP. In this tutorial, we will install a Redis server as an object cache for DB queries, and configure WordPress to use it.


  1. Set Up Server Monitoring with New Relic
  2. Benchmark performance under load without caching
  3. Install the latest version of Redis and verify it is working

Allocate Memory to Redis and Configure an Eviction policy

Now we need to configure our Redis cache policy, we will set the maximum memory available to it for caching and also the eviction policy for when the cache memory becomes full and we need to replace old data with new data.

sudo nano /etc/redis/redis.conf
maxmemory 128mb
maxmemory-policy allkeys-lfu
sudo service redis-server restart
sudo service php7.0-fpm restart

Enable cache settings in wp-config.php

Next we need to edit our WordPress ‘wp-config.php’ file to add a cache key salt with the name of your site, and define ‘WP_CACHE’ as true to create a persistent cache with the WordPress Redis Object cache plugin we will install later:

sudo nano /var/www/html/wp-config.php
define( 'WP_CACHE_KEY_SALT', '' );
define( 'WP_CACHE', true );

Install a Redis Object Cache Plugin

We need to install a Redis Object Cache plugin in order for WordPress to make use of Redis as an object cache, there are several in the WordPress plugin repository, but we will use the Redis Object Cache plugin by Till Krüss.

Related Blog Posts

Installation of LibreNMS on Ubuntu

In this tutorial, we will install and configure LibreNMS on Ubuntu 16.04 with an Alibaba Cloud Elastic Compute Service (ECS) instance.

Install Craft CMS on a LEMP Stack on Alibaba Cloud

There are many PHP based Content Management Systems (CMS) that you can run on an Alibaba Cloud ECS Instance with a LEMP stack. Of these, Craft CMS is probably one of the slickest.

Related Market Products

Wordpress on LAMP Ubuntu 14.04 64bits powered by IGS

Integrated with one of the world’s most popular web publishing platforms for building blogs and websites. We, IGS, provide a list of images pre-integrated with most popular software for web solution. It includes ready-to-run versions of Apache/Nginx, MySQL, PHP, phpMyAdmin and all of the other software required to run each of those components. IGS image greatly simplifies the development and deployment of web applications.

Related Documentation

PHP_ memcached

If you have a PHP Memcache environment, pay attention to the prompts during the tutorial to avoid overwriting the production environment, which may render the business unavailable. We recommend that you back up the data before upgrading or compiling the environment.


Security Center is available in Basic Edition and Enterprise Edition.
Webshell detection: checks both instances/servers and networks for web scripts, such as PHP, ASP, and JSP files.
Suspicious database commands: Suspicious commands in databases, such as MySQL, PostgreSQL, SQLServer, Redis, and Oracle.

Related Products

ApsaraDB for Redis

ApsaraDB for Redis is an automated and scalable tool for developers to manage data storage shared across multiple processes, applications or servers.

ApsaraDB for Memcache

ApsaraDB for Memcache is a managed memory based caching service, which supports high-speed access to queries and data. ApsaraDB for Memcache improves the response of dynamic websites or applications by relieving the load on the backend database as cache data is stored in-memory.

Related Course

Alibaba Cloud Elastic Architecture and Case Study

The objective of this course is to learn the core services of Alibaba Cloud’s Elastic Architecture: Auto-Scaling, CDN, Redis, and Memcache by studying some use cases.

Follow me to keep abreast with the latest technology news, industry insights, and developer trends.