Install Redis Cache on Magento 2 With Step By Step Guide

by Fayyaz Khattak  February 22, 2016

Store Owners, Merchants as well as Developers are now adopting Magento 2 because of its new design, the increase in security & performance, memory optimization, and support with latest technology trends. But still everyone is looking and trying to improve the Magento site’s performance and responsiveness using different optimization techniques.

Most of the developers always go through different approaches like enabling default cache and compilation of Magento 2, but, unfortunately, utilizing the file-system based cache for a Magento site simply makes your site run a bit faster instead of giving it a boost.

So the question raised is that, what would you use? A file-system based cache or any other option by which you’ll be able to work and load your site faster? What if you develop your Magento store with a faster backend cache?

Magento 2 Redis Cache

Sounds interesting, right?

Same as our previous article How To Setup Redis Cache On Magento Backend, let’s talk about Redis Cache and its configuration on Magento 2.

Why is Redis better?

Redis is a very fast backend cache with full cache tag support, no need for slow-level file system cache and on high traffic Magento stores, the performance is great and stable. It is also highly recommended in multi-server environments.

Advantages

The following are further advantages of Redis with Magento 2:

  • Decreases the memory usage with the backend support of tag-based cache cleanup without any foreach loops.
  • The Redis backend works by indexing tags in files so that tag operations do not require a full scan of every cache file.
  • The metadata and the cache record are stored in the same file rather than separate files resulting in fewer file stat, read, write, lock, and unlink operations.
  • Redis supports on-disk save and master/slave replication.

Requirements

The following are the prerequisites to configure Redis Cache on Magento 2:

  • Redis Server
  • PHP Redis Extension

The latest versions are always preferable.

Installation

Cloudways servers are based on Redis Cloud hosting which provides unbeatable performance. If you are a Cloudways user, you only have to activate Redis or if you have your own web server, you need to install Redis and PHP Redis Extension on your server.

Activate Redis on Cloudways

Login to your Cloudways account. Go to “Server Management”, dropdown “Server Settings & Packages” and click “Packages” tab. You’ll see the Redis option, change status to “Yes” and click Save button. After that, you’ll see a waiting screen for the server where Redis is being activated.

Redis on Magento

After Redis activation, Go to “Server Management”, dropdown “Manage Services” and verify that Redis status shows green signal, its mean Redis has been successfully activated on your server. For more information, see this article Activate Redis On Your Cloud Server Now.

Configure Redis Cache

In this step, we are going to configure Redis on Magento 2. You need to add Redis configuration in Magento2_ROOT_Directory > app > etc > env.php file. In this env.php file, you would find a large PHP array with different settings and configuration. We would add the following configuration at the end of this file right before “);” which is the ending parenthesis of PHP array:

Save your env.php file and clear Magento 2 cache with php bin/magento cache:flush command.

Monitor & Verify Redis Cache

To verify whether you have correctly configured Redis cache on Magento 2, you can use the following commands in the SSH terminal:

  • Type redis-cli monitor and refresh your site, you will see an output on your screen.
  • Type redis-cli ping and you’ll get a reply of ‘PONG’ which means everything is looking good.
  • Type php -m | grep redis by which you’ll see ‘redis’ in reply, which confirms that the PHP Redis Extension is ready to go.

Also, if you need to clear Redis cache, simple type redis-cli FLUSHALL and an OK reply will confirm that your cache has been cleared successfully.

Start Creating Web Apps on Managed Cloud Servers Now!

Easy Web App Deployment for Agencies, Developers and E-Commerce Industry

About Fayyaz Khattak

Fayyaz is a Magento Community Manager at Cloudways - A Managed Magento Hosting Platform. His objective is to learn & share about PHP & Magento Development in Community. Fayyaz is a food lover and enjoys driving. You can email him at m.fayyaz@cloudways.com

Stay Connected:

You Might Also Like...

  • No need to use “Cm_Cache_Backend_Redis” since 1.8 magento support the statement “Mage_Cache_Backend_Redis”

  • moy2010

    Please do a similar guide about installing Redis on Prestashop!

  • SINO NING

    goode