How to Setup Memcached for Magento on AWS EC2 with CentOS/RedHat

Boost your Magento performance with Memcached on AWS EC2 using CentOS or RedHat. Learn the step-by-step setup guide with examples.5 min


How to Setup Memcached for Magento on AWS EC2 with CentOS/RedHat

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:

  1. An active AWS EC2 instance with CentOS or RedHat installed.
  2. Magento installed and configured.
  3. SSH access to your EC2 instance.
  4. 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

  1. Open the Magento app/etc/env.php configuration file.
  2. 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

  1. Monitor Performance: Use tools like htop or top to monitor Memcached’s resource usage.
  2. Check Logs: Review logs in /var/log/messages for any errors related to Memcached.
  3. 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,

  1. How to Connect AWS EC2 Instance to Your Domain Name | Easy Guide
  2. Best 50 Most Useful APIs for Developers [New List for 2025]

adsense


Discover more from 9Mood

Subscribe to get the latest posts sent to your email.


Like it? Share with your friends!

What's Your Reaction?

Lol Lol
0
Lol
WTF WTF
0
WTF
Cute Cute
0
Cute
Love Love
0
Love
Vomit Vomit
0
Vomit
Cry Cry
0
Cry
Wow Wow
0
Wow
Fail Fail
0
Fail
Angry Angry
0
Angry
Rakshit Shah

Legend

Hey Moodies, Kem chho ? - Majama? (Yeah, You guessed Right! I am from Gujarat, India) 25, Computer Engineer, Foodie, Gamer, Coder and may be a Traveller . > If I can’t, who else will? < You can reach out me by “Rakshitshah94” on 9MOodQuoraMediumGithubInstagramsnapchattwitter, Even you can also google it to see me. I am everywhere, But I am not God. Feel free to text me.

0 Comments

Leave a Reply

Choose A Format
Story
Formatted Text with Embeds and Visuals
List
The Classic Internet Listicles
Ranked List
Upvote or downvote to decide the best list item
Open List
Submit your own item and vote up for the best submission
Countdown
The Classic Internet Countdowns
Meme
Upload your own images to make custom memes
Poll
Voting to make decisions or determine opinions
Trivia quiz
Series of questions with right and wrong answers that intends to check knowledge
Personality quiz
Series of questions that intends to reveal something about the personality
is avocado good for breakfast? Sustainability Tips for Living Green Daily Photos Taken At Right Moment