Install and Configure Memcached on CentOS 7

By | October 29, 2016


Memcached is a distributed, high-performance, in-memory caching system that allows you to improve and speed up the performance of dynamic web applications by caching data and objects in memory. It is primarily used to speed up sites that make heavy use of databases.

Memcached is also used to cache entire database tables and queries to improve the performance of the database. Memcached is free and is used by many sites like Facebook, YouTube and Twitter.

This tutorial shows you how to install and configure Memcached on CentOS 7.


  • A server running CentOS 7 with Apache and PHP installed

Installing Memcached

First make sure all packages are up to date:

sudo yum -y update

Now execute the following commands to install Memcached:

sudo yum -y install memcached

Start Memcached services and add it to automatically start on your system start-up with:

sudo systemctl enable memcached
sudo systemctl start memcached

Configure Memcached

The default Memcached configuration file is located in the /etc/sysconfig directory.

To configure Memcached, edit the /etc/sysconfig/memcached file:

sudo nano /etc/sysconfig/memcached

Set or update parameters as follows, customizing them to your needs:


This is a brief description of the parameters:

**PORT**: The default port used by Memcached to run.
**USER**: The user Memcached runs as.
**MAXCONN**: The maximum number of allowed connections to Memcached. You can increase to any number based on your requirements.
**CACHESIZE**: The cache size for memory.
**OPTIONS**: Set IP address of server, so that Apache or Nginx web servers can connect to it.

Exit and save the configuration file, and then restart Memcached:

sudo systemctl restart memcached

Run the following command to verify that Memcached is running:

sudo netstat -tulpn | grep :11211

You will see the following output:

Netstat output when using Memcached

To check the stats of the server using memcached-tool:

sudo memcached-tool stats

Installing the Memcached PHP Extension

You can install PHP extension to work with Memcached daemon with the command:

sudo yum install php-pecl-memcache

Now, restart Apache so that the changes take place:

sudo systemctl restart memcached
sudo systemctl restart httpd

To test Memcached PHP extension, create an info.php file in apache web root directory.

sudo nano /var/www/html/info.php

Add the following content:


Save the file and access it at http://your_server_ip/info.php in a web browser.

When the PHP info page is rendered in your browser look for this section:

Output of a PHP info page with Memcached installed

Installing the Memcached Python Library

You can install Memcached Python library by running the following command:

sudo yum install python-memcached

Now, restart the Apache service so that the changes take place:

sudo systemctl restart httpd

Congratulations! You have successfully installed Memcached

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.