In this tutorial we’ll learn how to install Memcached on CentOS 7. We will also install and configure its prerequisites. Memcached is a distributed, high-performance, in-memory caching system that is largely used to speed up sites that make heavy use of databases. It can however be used to store items of any kind. Nearly every popular CMS has a plugin or module to make the most of memcached, and lots of programming languages have a memcached library, including PHP, Perl, Ruby, and Python. Memcached runs in memory and is thus quite speedy, as it doesn’t need to write data to disc.
I recommend to use a minimal CentOS server setup as a basis for the tutorial, that can be a virtual or a root server image with an CentOS 7 minimal install from a web hosting company or you use our minimal server tutorial to install a server from scratch.
Install Memcached on CentOS 7
Step 1. First, ensure your system is fully up-to-date by running the following:
yum -y update
Step 2. Installing Memcached.
Install Memcached using the following command:
yum -y install memcached
Then installing PHP Memcached extension and related packages is now as simple as running just one command:
yum -y install php-pecl-memcache
The package is now installed, but it must also be started. We must also configure it to run on boot so it launches when your server comes up:
systemctl start memcached.service systemctl enable memcached.service
Step 3. Configure Memcached.
Memcached must now be configured. Weâll edit its configuration file to make a few key optimizations:
sudo nano /etc/sysconfig/memcached
Set or update parameters as follows, customizing them to your needs:
PORT="11211" USER="memcached" MAXCONN="1024" CACHESIZE="64" OPTIONS=""
Exit and save the configuration file, and then restart Memcached:
systemctl restart memcached.service
Run the following command to verify that Memcached is running:
netstat -tulpn | grep :11211