Install Memcached in Magento 2
Vinh Jacker | 11-04-2024
If you have a Magento 2 store with many unique products, what happens if your customers wait forever for the page to load? Frustration sets in and comes with its consequence: low sales. This is where Memcached comes in! Memcached can make your store run faster, keep customers happy, and help your business grow.
This guide will take you through the steps to set up and use Memcached with Magento 2. We’ll go from the basics of installing Memcached on your server to configuring it within your Magento store. If you aim to improve your store’s performance or explore more effective caching solutions, this guide will give you the information you need to get started.
What Is Memcached?
Memcached is a distributed memory caching technology that works very quickly and speeds up dynamic web apps by lowering the load on databases. It stores data in memory (RAM) to reduce the time taken to retrieve information, thus enhancing your website’s overall performance and scalability.
This is especially crucial to Magento stores since intuitive data analysis can significantly improve the site’s performance.
Step 1: Install the Memcached service
If you are using Cloudways, it is easy to install. Here are the steps to enable Memcached in Cloudways.
Step 1. Log into the Cloudways Platform.
- Access your Cloudways account and go to the server management area.
Step 2: Enable/Install Memcached
-
Select a Server you want to setup
-
Navigate to the Server Management tab.
-
Go to Manage Services.
-
Find Memcached in the list of available services and click switch it on.
Step 3: Verify Magento 2 Memcached on the Server
After enabling Memcached, it’s wise to check if it’s running correctly. You can use tools like telnet or SSH to connect to your server and run commands like ps aux | grep memcached to see if the Memcached process is active. |
This command will let you see whether Memcached is operating if have root access to the server:
netstat -ap | grep 11211
After that, create a file named phpinfo.php in the root directory of your site (where the public_html folder is located) and add this code:
<?php
phpinfo();
?>
Once you’ve confirmed that Memcached is active, we can move on to configuring Memcached for Magento 2.
Step-by-Step Guide to Configure Memcached with Magento 2
Install Memcached on Your Server
First, you need to install Memcached on your server. You can do this using the following command:
sudo apt-get install memcached
Install PHP Memcached Extension
Next, install the PHP extension for Memcached:
Run the command: sudo apt-get install php{php_version}-memcached
sudo apt-get install php8.3-memcached
Verify Memcached Installation
Ensure Memcached is running by using the following command:
ps aux | grep memcached
Or use command sudo service memcached status
Step 2: Configure Magento 2 Memcached
- Edit the env.php file located in the app/etc directory of your Magento installation. Add or modify the following lines to configure session and cache storage:
'session' => [
'save' => 'memcached',
'save_path' => '127.0.0.1:11211'
],
'cache' => [
'frontend' => [
'default' => [
'backend' => 'Cm_Cache_Backend_Memcached',
'backend_options' => [
'servers' => [
[
'host' => '127.0.0.1',
'port' => '11211'
]
],
'compression' => false
]
],
'page_cache' => [
'backend' => 'Cm_Cache_Backend_Memcached',
'backend_options' => [
'servers' => [
[
'host' => '127.0.0.1',
'port' => '11211'
]
],
'compression' => false
]
]
]
]
- Once you’ve made these changes, save and close the env.php file.
- After making these changes, restart your web server and clean magento cache to apply the new configuration:
sudo service apache2 restart;
php bin/magento cache:flush;
Next, let’s check your magento site.
Magento Memcached FAQs
1, Why is Memcached good for Magento Stores?
-
Better Load Times: This means your database is not as burdened and your pages take time to load since they are holding data that is frequently referenced.
-
Better User Experience: Whenever your pages open quickly, the customer’s shopping process will be easier and less time-consuming.
-
Reduced Server Load: What happens when you send database queries to Memcached?
Your database server’s load reduces, making it possible for your database server to accommodate more people and activities.
- Cost Efficiency: Memcached reduces running costs by reducing the degree to which it relies on pricy database hardware enhancements.
2, Is Memcached free?
Yes, Memcached is free to use. It is an open-source project, meaning you can download, install, and use it without licensing fees.
3, Where is the Memcached config file in the Magento application?
The /etc/sysconfig
directory contains the default Memcached configuration file.
Final Words
Using Memcached enhances the efficiency of the Magento store, focusing on customers’ experience and potential sales boost. Although the configuration might appear rather specialized, the advantages are definitely worth the trouble. Hence, go for Memcached now and witness your Magento store open a new chapter of high performance!
Sale Boosters Pack for Magento 2
Equip helpful functions to level up your sales in only one package
Check it out!