How to Setup Memcached for Magento on AWS EC2 with CentOS/RedHat
Optimizing Magento’s performance is crucial for ensuring a seamless shopping experience. Memcached, a distributed memory object caching system, significantly enhances Magento’s speed by caching frequently accessed data. In this guide, you’ll learn how to set up Memcached for Magento on an AWS EC2 instance running CentOS or RedHat.
Prerequisites
Before diving into the setup, ensure you have the below accesses:
- An active AWS EC2 instance with CentOS or RedHat installed.
- Magento installed and configured.
- SSH access to your EC2 instance.
- Basic knowledge of Linux commands.
Step 1: Update Your System
Log into your AWS EC2 instance using SSH and update the system packages to ensure compatibility.
sudo yum update -y
Step 2: Install Memcached
To install Memcached, use the package manager:
sudo yum install memcached -y
Once installed, start the Memcached service and enable it to start automatically on boot:
sudo systemctl start memcached sudo systemctl enable memcached
Verify the installation:
memcached -V
Step 3: Configure Memcached
Edit the Memcached configuration file to optimize its performance:
sudo nano /etc/sysconfig/memcached
Modify the following parameters as per your server requirements:
PORT="11211" USER="memcached" MAXCONN="1024" CACHESIZE="64" OPTIONS="-l 127.0.0.1"
Save the file and restart the Memcached service:
sudo systemctl restart memcached
Step 4: Install PHP Memcached Extension
Magento requires the PHP Memcached extension for integration. Install it with the following command:
sudo yum install php-pecl-memcached -y
Restart the webserver to apply the changes:
sudo systemctl restart httpd
Step 5: Verify Memcached Integration with Magento
- Open the Magento
app/etc/env.php
configuration file. - Add the following lines to enable Memcached as a cache backend:
'cache' => [ 'frontend' => [ 'default' => [ 'backend' => 'Cm_Cache_Backend_Redis', 'backend_options' => [ 'servers' => [ [ 'host' => '127.0.0.1', 'port' => '11211', ], ], 'compress_data' => 1, ], ], ], ],
3. Save the file and clear Magento’s cache using:
php bin/magento cache:flush
Step 6: Test Memcached Functionality
To confirm Memcached is working as expected, use the telnet
command:
telnet 127.0.0.1 11211
If successful, you will see the Memcached prompt. Type stats
to view server statistics:
stats
Exit the session by typing:
quit
Step 7: Monitor and Troubleshoot
- Monitor Performance: Use tools like
htop
ortop
to monitor Memcached’s resource usage. - Check Logs: Review logs in
/var/log/messages
for any errors related to Memcached. - Common Issue: If Magento doesn’t connect, verify that the
OPTIONS
parameter in the Memcached config file allows Magento’s IP address.
Conclusion
By following this guide, you’ve successfully set up Memcached for Magento on an AWS EC2 instance running CentOS or RedHat. This setup ensures faster page load times, reduced database load, and an improved user experience for your Magento store.
For more advanced configurations or troubleshooting, refer to the official Magento and Memcached documentation.
You may also like to read,
- How to Connect AWS EC2 Instance to Your Domain Name | Easy Guide
- Best 50 Most Useful APIs for Developers [New List for 2025]
Discover more from 9Mood
Subscribe to get the latest posts sent to your email.
0 Comments