Install memcached on CentOS 5

Reading Time: 2 minutes
Please note that this article is considered legacy documentation because CentOS 5 has reached its end-of-life support.

Memcached is a distributed, high-performance, in-memory caching system that is primarily used to speed up database-heavy sites, but can be used to stores objects of any kind.

Nearly every popular CMS has a plugin or module to take advantage of it, and many programming languages have a memcached library, including PHP, Perl, Ruby and Python. Memcached runs in-memory and doesn’t need to write to disk, so it is incredibly fast. We’ll discuss setting up memcached for specific CMSes in later articles, but for now let’s get memcached up and running on your CentOS 5 server.

First, we start with installing libevent; at least version 1.1 is required. This one’s easy, we can install it using yum.

yum install libevent libevent-devel

Now, onto memcached. Change your working directory to /usr/local/src and download the memcached source:

cd /usr/local/src

Uncompress the tarball you download and change into the directory that is created:

tar xvzf memcached-1.4.1.tar.gz
cd memcached-1.4.1

Memcached is actively developed, so the version used in this tutorial may be outdated by the time you read this. As of this writing, 1.4.1 is the latest stable version. Check here for a newer version before proceeding with the installation.

Up next, configuring our makefile. This can be as simple as:


Additional configure flags are available and can improve performance if your server is capable. For 64-bit OSes, you can enable memcached to utilize a larger memory allocation than is possible with 32-bit OSes:

./configure --enable-64bit

If your server has multiple CPUs or uses multi-core CPUs, enable threading:

./configure --enable-threads

If you’ve got both a 64-bit OS and multiple CPUs, use both:

./configure --enable-threads --enable-64bit

Once the configuration script completes, build and install memcached:

make && make install

Finally, start a memcached server:
memcached -d -u nobody -m 512 -p 11211

Put another way, the previous command can be laid out like this:

memcached -d -u [user] -m [memory size] -p [port] [listening IP]

Let’s go over what each switch does in the above command:

Tell memcached to start up as a background daemon process
Specify the user that you want to run memcached
Set the memory that you want to be allocated by memcached
The port on which memcached will listen.

And that’s it. Now go forth and speed up your sites!

Avatar for J. Mays

About the Author: J. Mays

As a previous contributor, JMays shares his insight with our Knowledge Base center. In our Knowledge Base, you'll be able to find how-to articles on Ubuntu, CentOS, Fedora and much more!

Latest Articles

Innovative armor — exploring ThreatDown’s impact on cyber defense

Read Article

Using a Cloudflare Argo Tunnel with load balancing

Read Article

Controlling PHP settings with a custom php.ini file

Read Article

Linux dos2unix command syntax — removing hidden Windows characters from files

Read Article

Change cPanel password from WebHost Manager (WHM)

Read Article