• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
NameHero Blog

NameHero Blog

Web Hosting Tips & Resources From NameHero

  • Hosting
    • Web Hosting
    • VPS Hosting
    • WordPress Hosting
    • WooCommerce Hosting
  • Reseller
  • Enterprise
  • Domains
  • Account
  • Blog Home
  • Categories

How To Install Redis For WordPress On A VPS

Bhagwad Park

Published on: December 22, 2021

Categories: WordPress 0

Earlier, I’d written a tutorial on how to install memcached on a VPS that integrates with PHP. In this tutorial, I’ll write about how to do the same with Redis. Like memcached, Redis is another caching mechanism that can speed up reads and writes by using your (much faster) RAM instead of accessing the database or the disk. Here’s how to install and configure Redis with your VPS.

Note: As before, for these examples, I’m using CentOS 7 on Linux. If you have a different distribution, the installation commands will differ, but hopefully nothing will be too different. Also, most of these commands will require root privileges, so make sure you’re using an account that can run sudo commands.

To use Redis for WordPress requires at least 3 steps:

  1. Installing the system service on the VPS
  2. Installing the correct PHP extension
  3. Installing a plugin that can use Redis

Here are the steps one by one.

Step 1: Install the Redis System Service

First, we update the yum packages to make sure we’re getting the latest information:

yum update

Then:

yum install redis

Once the installation is complete, enable and start the redis service:

systemctl start redis
systemctl enable redis

Step 2: Configure Redis maxmemory and Ensure it’s Bound to the Local Port

By default, Redis listens to all interfaces on all ports. This makes it susceptible to DDoS attacks. So first we want to bind Redis to only the local IP address: 127.0.0.1. It should already be enabled by default, but no harm in checking.

Navigate to the Redis config file and open it in a text editor:

vi /etc/redis.conf

Scroll down till you see the following line:

bind 127.0.0.1

Ensure that there’s no hash (#) in front of it, so the line is uncommented. If there is a hash, remove it.

Next, go down till you see the following line:

maxmemory

Uncomment it, and set it to the maximum memory that you want Redis to use. For my installation, I used:

maxmemory 256M

For me, 256 MB is more than enough for Redis. Your limit might be different.

Once you’ve made the changes, restart redis:

systemctl restart redis

Step 3: Install the Redis PHP Agent

The next step is to integrate Redis with PHP. Search the repo for the version of Redis that integrates with your PHP version. Mine is PHP 7.4, so I use the following command:

yum search redis | php74

I get an output like this:

Get the Correct Version of Redis for your PHP Version
Get the Correct Version of Redis for your PHP Version

Over here, we see that the latest PHP 7.4 extension for communicating with the Redis server is:

php74-php-pecl-redis5

So we use yum to install this package:

yum install php74-php-pecl-redis5

Once this is done, restart your server and PHP. Now you’re set up with Redis! You can verify this with a phpinfo(); command and check that the Redis module exists.

Step 4: Install a Plugin that Can use Redis

The final step is to install a plugin that actually allows WordPress to access the Redis cache for its operations. There are two well-known plugins that do this:

  1. The Redis Object Cache Plugin
  2. W3 Total Cache

For the latter, you have to specifically go into the “General” tab and select Redis for each of the Page, database, and Fragment caches like this:

Using Redis for Caching with W3 Total Cache
Using Redis for Caching with W3 Total Cache

If you’ve performed all the previous steps correctly, then the above option should be available to you and not greyed out.

Note: The jury is out on database caching – especially when the W3 Total Cache Object caching is already enabled. The documentation suggests leaving it out, so I suggest that’s what you do. You can always try enabling it to see how it works for you.

And that’s it! You’ve successfully installed Redis to speed up your WordPress site!

Bhagwad Park Profile Picture
Bhagwad Park

I’m a NameHero team member, and an expert on WordPress and web hosting. I’ve been in this industry since 2008. I’ve also developed apps on Android and have written extensive tutorials on managing Linux servers. You can contact me on my website WP-Tweaks.com!

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Follow & Subscribe

Exclusive promos, content and more!

Most Popular Posts

Speed up your site: solving the WordPress slowdown

NameHero’s Recommended WordPress Plugin and Theme Setup (2023)

How To Increase The InnoDB Buffer Pool Size

How To Fix A Stuck All-in-One WP Migration Import

How To Add A Subdomain In Cloudflare

Top Categories

  • WordPress
  • Website Performance
  • Web Hosting
  • Resellers
  • Website Security
  • Website Development
  • VPS Hosting
  • SEO Tips
  • Announcements
  • Domain Registration
NameHero

NameHero proudly provides web hosting to over 40,000 customers with 99.9% uptime to over 750,000 websites.

  • Master Card
  • Visa
  • American Express
  • Discover
  • Paypal
Products
  • Web Hosting
  • VPS Hosting
  • WordPress Hosting
  • WooCommerce Hosting
  • Reseller Hosting
  • Enterprise Hosting
  • Domains
Help & Support
  • NameHero Blog
  • Knowledgebase
  • Announcements
  • Affiliates
Company
  • About Us
  • Contact Sales
  • Reviews
  • Uptime
  • We're Hiring

Copyright © 2023 NameHero, LLC. All rights reserved.

  • Privacy Policy
  • Terms of Use
  • Acceptable Use Policy
  • Payment Policy
  • DMCA