Please note: This requires some technical changes in your Magento application. We recommend that developers apply this method to a staging/development environment first.
The Magento CMS supports many backend caches that commonly use APC, Full Page Cache, and Varnish Cache. Online store owners, merchants, and developers can regularly use different optimization techniques to improve their Magento store’s performance and responsiveness.
For an exceptionally versatile data store that allows for the use of different procedures, applications, and server configurations, you should seriously consider installing the Magento 2 Redis cache.
Redis is a robust caching system whose use is fast becoming popular with Magento and other web applications. This is why it is essential that developers understand how to configure the Magento Redis cache through the backend without any hiccups.
- What is Redis Cache?
- Why is Redis Better?
- Before You Enable Redis Cache For Magento Store
- Magento Redis Requirements
- Magento Redis Quick Start
- Activate Redis Cache on Cloudways
- Magento 2 Redis Configuration
- Magento 1 Redis Configuration
- Monitor and Verify Magento Redis Cache
- Final Thoughts
What is Redis Cache?
Redis cache lets you impart cross-stage, cross-server, or cross-application, which makes it an excellent choice for a number of use cases. Its speed is another factor that makes it an incredible cache layer.
Redis has virtual memory, where once in a while utilized keys are swapped out to circle so that only the keys needed to fit into the memory are used. Furthermore, the use cases for Redis are those where it’s feasible for the complete information set to fit into the memory.
The essential point of interest in utilizing Redis cache is that store labels are upheld. The moderate-level file system cache no longer needs to be utilized. Magento Redis cache backend is prescribed in multi-server situations where you have more than one web server.
Experience the Cloudways Magento 2 Demo Store – No tech skills needed!
Experience a fully functional Magento 2 store built on top of renowned Cloudways hosting to deliver the fastest speeds.
Why is Redis Better?
Redis is a high-speed backend cache with full cache tag support and no need for low-level file system cache. Its performance is stable for high traffic Magento stores. It is also highly recommended in multi-server environments.
The Advantages of Using Magento 2 Redis
If you are using Magento 2 Redis, you get the following advantages:
- It decreases the memory usage with the backend support of tag-based cache cleanup without any FOREACH loops.
- The Magento 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 stats, read, write, lock, and unlink operations.
- Redis supports on-disk save and master/slave replication.
Scale Your Magento 2 Store With Ease
One-Click Magento 2 installation with your own managed hosting solution.
Before You Enable Redis Cache For Magento Store
Like you would for every procedure that directly affects your server and your Magento site, you should take precautions before enabling any technological stacks like Magento Redis cache.
Backup Your Server
The first thing is to back up your Magento store and server configuration so that you have a safe restore point to revert in case anything goes wrong.
Use a Staging Site to Test
You should test all site changes on a clone or staging environment. Once you are satisfied, simply “push” the changes to the live site.
Magento Redis Requirements
Here are the prerequisites to configure Magento Redis Cache on hosting server:
- Redis Server
- PHP Redis Extension
It’s always preferable to use the latest versions.
Magento Redis Quick Start
Cloudways servers are based on Redis Cloud Hosting, which offers unbeatable performance. If you are a Cloudways user, you only have to activate Redis. Or, if you have your own Magento hosting server, you need to install Redis and PHP Redis Extension on your server. Without further ado, let’s move on to the configuration part of Magento Redis cache.
Activate Redis Cache on Cloudways
Login to your Cloudways account, and click on your Magento Server.
Under Server Management, click Settings & Packages.
Then, click the Packages tab.
You’ll see the Redis option. Click the INSTALL button to install Redis.
After that, the waiting screen will appear as Redis is installed and activated on your server.
Once it’s done, go to Manage Services and verify the Redis status. If it shows a green signal, Redis has been successfully installed and activated on your server.
Magento 2 Redis Configuration
Now we will configure Magento Redis for version 2.x. You are required to add a Redis configuration script in the env.php file that can be found in Magento2_ROOT/app/etc directory.
In the env.php file, different settings and configurations are defined in a PHP array. We will add the following code at the end right before ); which is the ending parenthesis of PHP array.
'cache' => [ 'frontend' => [ 'default' => [ 'backend' => 'Magento\\Framework\\Cache\\Backend\\Redis', 'backend_options' => [ 'server' => '127.0.0.1', 'database' => '0', 'port' => '6379' ], ], 'page_cache' => [ 'backend' => 'Magento\\Framework\\Cache\\Backend\\Redis', 'backend_options' => [ 'server' => '127.0.0.1', 'port' => '6379', 'database' => '1', 'compress_data' => '0' ] ] ] ],
Save the env.php file and clear the Magento 2 cache with php bin/magento cache:flush command.
Magento 1 Redis Configuration
In this step, you need to edit a couple of files. In Magento 1.x, there is a built-in Redis module that can be found in Magento1_ROOT/app/etc/modules/Cm_RedisSession.xml.
Open Cm_RedisSession.xml in a text editor, where you will find the following code.
<config> <modules> <Cm_RedisSession> <active>false</active> <codePool>community</codePool> </Cm_RedisSession> </modules> </config>
Change the value of <active> to true.
Next, you must copy and place the following code in Magento 1 root/app/etc/local.xml file. Open your local.xml in a text editor. Under <global> tag, paste this code.
<cache> <backend>Cm_Cache_Backend_Redis</backend> <backend_options> <server>127.0.0.1</server> <port>6379</port> <persistent></persistent> <password></password> <force_standalone>0</force_standalone> <connect_retries>1</connect_retries> <read_timeout>10</read_timeout> <automatic_cleaning_factor>0</automatic_cleaning_factor> <compress_data>1</compress_data> <compress_tags>1</compress_tags> <compress_threshold>20480</compress_threshold> <compression_lib>gzip</compression_lib> <use_lua>0</use_lua> </backend_options> </cache>
Once it’s done, save your local.xml file. Then navigate to Magento1_ROOT/var/cache and delete all files and folders to clear the Magento cache.
Monitor and Verify Magento Redis Cache
To verify whether you have correctly configured Redis cache on Magento, 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 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, simply type redis-cli FLUSHALL and an OK reply will confirm that your cache has been cleared successfully.
Enabling Magento Redis Cache on your store’s backend will make your Magento store smoother and faster. This is why Magento developers must know how to set up Redis cache in Magento backend.
The optimization formula of Cloudways uses Nginx, Apache, and now, Redis. This unique combination significantly improves the performance of your web applications. Sign up now for a free trial of Cloudways, and experience the fastest performance of your Magento store.
Abdur Rahman is the Magento whizz at Cloudways. He is growth ambitious, and aims to learn & share information about Ecommerce & Magento Development through practice and experimentation. He loves to travel and explore new ideas whenever he finds time. Get in touch with him at [email protected]