How to speed up your WordPress site with Redis Cache on AWS Lightsail

In this video tutorial I will show you how to install and configure Redis cache. Redis is a object level caching mechanism that will cache your database queries in memory. It’s technically a data store itself but using it with your WordPress database will speed up your site.
Also object level caching is different from a CDN; I’ve done a video tutorial on setting up a Lightsail CDN service with WordPress, you may want to checkout if your interested. CDN caches your websites static assets at the edge level so its replicating all of your images/CSS/JS and other static files all around the world so that when a visitor requests the site those files are served from the closest location to that visitor making it faster. Redis is essentially caching your dynamic queries in memory making the site faster as well.

Keep in mind I am using Bitnami WordPress blueprint in AWS lightsail for this tutorial. If you have a different setup of LAMP/Wordpress, some of these commands will be slightly different. Also for these steps you will need your own VM or full access to your server instance via SSH. If you have shared hosting this is not for you; however your hosting provider may already have all these configurations done for you so you might just have to perform the WordPress steps. Check with your hosting provider. If they don’t have this and are not willing to enable it for you then its’ time to switch hosting providers. AWS Lightsail is great platform to migrate to from a shared hosting environment.

Steps:

  1. SSH into your server and run update commands, especially if this is a new instance
    1. sudo apt-get update
    2. sudo apt-get upgrade
  2. Install Redis Server
    1. sudo apt-get install redis-server php-redis
  3. Add or uncomment following lines to the redis.conf files at /etc/redis/redis.conf
    1. maxmemory 256mb
    2. maxmemory-policy allkeys-lfu
  4. Restart services
    1. sudo systemctl restart redis-server
    2. sudo /opt/bitnami/ctlscript.sh restart php-fpm
  5. Install php-redis extension
    1. sudo pecl install redis
  6. Update php.ini to include the new extension
    1. sudo vi /opt/bitnami/php/etc/php.ini
    2. add extension=redis.so to the file and save
  7. Restart all services
    1. sudo /opt/bitnami/ctlscript.sh restart
  8. Verify extension module is enabled
    1. php -m | grep redis
  9. Verify redis is installed and enabled
    1. redis-server --version
    2. netstat -lpan | grep :6379
  10. Install and activate redis plugin for WordPress
    1. Search for redis and install the redis plugin
  11. Modify the wp-config.php. Add the following two lines to the wp-config. Replace domain.com with your site domain
    1. define( 'WP_CACHE_KEY_SALT', 'domain.com' );
    2. define( 'WP_CACHE', true );
  12. Enable the Object cache in the Redis plugin.
  13. Monitor Redis activity on SSH
    1. redis-cli monitor

⌚ VIDEO TIMESTAMPS

  • 00:00 – Introduction
  • 00:58 – Redis and Caching Overview
  • 02:55 – Backup Reminder!
  • 05:09 – SSH into Server
  • 05:43 – Update and upgrade server packages
  • 06:24 – Install Redis server engine
  • 07:06 – Verify Redis installation
  • 07:50 – Configure Redis and Restart Services
  • 09:38 – Install PHP Redis extension
  • 10:05 – Update php.ini file to enable extension module
  • 11:07 – Restart LAMP Services
  • 12:00 – Install and Activate Redis Plugin for WordPress
  • 12:42 – Add Cache Configuration to wp-config.php file
  • 13:52 – Enable Object Cache in WordPress Settings
  • 14:20 – Redis CLI to monitor activity

All videos tutorials on the website as well as the YouTube channel aim to provide a simplified process for a specific scenario; there could be many different factors and unique use cases you may have. The tutorials may not cover every situation; so treat is as a starting point or learning concept to apply to your unique situations, and consider this inspiration but not prescription or explicit direction.

Scroll to Top