Magento executes multiple data and objects from its database when a customer visits and buy something from the store. These objects are defined in Magento core, PHP calls, and different blocks of the page which may reduce the performance of your Magento store.
If you want to optimize the speed of your Magento ecommerce store, one of the recommended solutions is to configure and use the Magento Memcached support.
What is Memcached?
Memcached is a distributed memory cache that speeds up large-scale web applications having dynamic databases. It reduces the load of database requests on a server and displays data through the cache whenever an external data source requests it.
Let’s take an example to understand Memcached better.
Suppose, you own a DVD store with lots of movies of different genres like action, drama, and comedy. You assign labels to the shelves that have the demanding movies and place them on the front counter.
Boost Your Magento Store Speed By 3x Times
Experience superior Magento performance with our advance caching and dedicated resources
Magento 2 Memcached Configuration on Server Using Cloudways
PHP has no native support for Memcached, which means you will need to go through a lot of hurdles to install Memcached extension for PHP to use it on your server.
But, if you become a Cloudways user, you won’t have to worry about a thing, as Cloudways takes care of all these hurdles and helps you enable Magento Memcached easily. That’s why I would recommend you to signup on Cloudways Platform and activate your account.
In this tutorial, I will use Cloudways to configure and run Magento Memcached.
All you have to do just log into your Cloudways Platform and find Memcached under the Manage & Services tab.
Verify Magento 2 Memcached on the Server
First of all, check if Magento 2 Memcached is active. To do so, type the following command in the terminal:
ps aux | grep memcached
You will see something like:
If you have root access to the server, try running the following command:
netstat -ap | grep 11211
Now, create a phpinfo.php file on the root directory (where public_html folder of the app is located) and enter the following code into it:
<?php phpinfo(); ?>
Open this file in the web browser and search for the term ‘Memcached’:
Now that I have verified that Memcached is active, let’s see how to configure Memcached with Magento 1 and Magento 2.
Configure Magento 2 Memcached
Magento 2 also supports Memcached for caching objects but it isn’t enabled by default. You need to make simple changes to the $Magento2Root/app/etc/env.php file to enable it.
In env.php, you will see a large number of PHP arrays with different settings and configurations. Open the file in your favorite code editor and locate the following code:
' array ( session' => 'save' => 'files', ),
Modify this chunk as:
'session' => array ( 'save' => 'memcached', 'save_path' => '<memcache ip or host>:<memcache port>' ),
Note that the default value for memcache ip is 127.0.0.1:11211. Similarly, the default value for memcache port is 11211.
Magento 2 Memcached Configuration Verification
To verify that Magento 2 has been configured appropriately to use Memcached, run the following command in the terminal and delete the content of some directories under your Magento 2 installation:
rm -rf var/cache/* var/page_cache/* var/session/*
Open your Magento 2 store in a browser and start browsing different pages to see if some page breaks down. Login to the admin panel as well to see if any error pops up. If so, it means Memcached has been configured with Magento 2 store, and it is working correctly.
If you face any processing or HTTP 500 (Internal Server Error) error, make sure that Memcached is running on the server, and that no errors exist in the env.php file.
Q. Why is Memcached good for Magento Stores?
Memcached does not support replication. Memcached is very good at handling high traffic websites just like Magento (Adobe Commerce). It can read lots of information at a time and give you back a great response time.
Q. Is Memcached free?
Memcached is free and open-source software, licensed under the Revised BSD license.
Q. Where is the Memcached config file in the Magento application?
The default Memcached configuration file is located in the /etc/sysconfig directory.
Performance issues during peak session is a serious concern for many online merchants. To overcome it, Magento has provided a few caching technologies that enhance its performance. Memcached is one of the caching mechanisms that have the power to handle complex data caching processes. It is a distributed memory caching system and deploys easily with any Magento store. It comes with a dynamic backend mechanism that efficiently handles cache data.
Besides this, if you work with the best Magento web hosting that will also give your application an extra boost in terms of perfromance. I hope, with the help of this guide you can easily configure Memcached to your Magento stores. If you face any issues while configuring Magento Memcached, feel free to leave a comment below.
Customer Review at
“Great speed, features, knowledgebase, dashboard, UX and fast, expert support. Very happy!”
Stefan [Management Consultant]
Fayyaz, a passionate Motorbike tourist, works as a Team Lead — Magento Community at Cloudways - A Managed Magento Hosting Platform. His objective is to learn & share about PHP & Magento Development in Community. You can contact him at [email protected]