×
Community Blog How to Install Redis Object Caching on WordPress

How to Install Redis Object Caching on WordPress

In this tutorial, you can get some information on the installation of a Redis object cache plugin 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.

Prerequisites

  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.

Open the Redis configuration file with your favorite text editor:

sudo nano /etc/redis/redis.conf

Now you need to uncomment the line '# maxmemory' and set your desired value, underneath this we will set the eviction policy, like so:

maxmemory 128mb
maxmemory-policy allkeys-lfu

Your conf file should look like this:

Redis conf file with Memory and Eviction policy configured

Remember to save the configuration file changes and restart both Redis and PHP-FPM:

sudo service redis-server restart
sudo service php7.0-fpm restart

If you have updated your php installation to php7.1 or php7.2 remember to make the appropriate changes.

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:

Open your 'wp-config.php' file for editing:

sudo nano /var/www/html/wp-config.php

Immediately after the WordPress unique Keys and Salts section, add the following with your site's url:

define( 'WP_CACHE_KEY_SALT', 'an-example-domain.com' );
define( 'WP_CACHE', true );

Your config file should now look like this:

redis wp-config.php

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.

Once the plugin is installed, go to the plugins settings and enable the object cache. If everything has been configured correctly, you should see a settings screen like this:

Redis Object Cache Plugin Settings - configured correctly

If you want to flush the Redis cache, you can do it from this screen. And if you would like to look at the details, you can go to WordPress: Performance Benchmarking & Installing Redis Object Caching.

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.

LibreNMS runs on the web server, written in PHP and uses MariaDB for database. So you will need to install Apache, PHP and MariaDB to your system.

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.

As Craft is built using the Yii high performance PHP framework, and adheres to modern PHP standards, it is also a very scalable and stable platform.

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.

Features

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 Redis supports advanced data structures, which are not readily achievable through databases such as leaderboard, counting, session, and tracking.

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.

0 0 0
Share on

Alibaba Clouder

2,605 posts | 747 followers

You may also like

Comments