How to install PHP memcache

February 28, 2012 — Leave a comment

This guide will help you install PHP Memcache on a CentOS server.

What is PHP memcache?

In my previous article, I showed you how to install Memcached, the service daemon. Now, if you would like your PHP software to interface with that daemon, you will want to install a PHP extension for it.

There are actually two separate implementations of a PHP Client that wraps the memcached (daemon); both are provided via the PECL library. One is called ‘memcache’ and the other is called ‘memcached’. I know that it is a little confusing that ‘memcached’ shares the same name as the daemon itself, but it IS a separate PHP wrapper.

This article will focus on installing ‘memcache’ as it is the most commonly used. You can use the information to install ‘memcached’ as well; the installation steps are the same. The main difference is that ‘memcached’ requires the libMemcached library. You can see a comparison of the two different PHP clients here:

Installation, the quick method

The easiest method is to simply use PECL’s ‘install’ command. This will grab the latest stable release, configure it with the default options, and add it to the server’s php.ini:

*Note: Un-installation is just as easy:

Installation, the manual method

The quick ‘install’ method uses the default configuration options and should serve most peoples’ purposes. However, if you need more control over the installation options, you can manually install from source and add it flags as you need.

Download the source package via PECL:

Unpack the tar and enter into the newly extracted directory (be sure to replace the X’s with your downloaded version):

Configure and install:

Verify the install

Verify the installation by displaying all the installed PHP modules. See if ‘memcache’ is listed:

Problems with manual installation

The ‘make install’ should load the module into your server’s extension directory automatically. However, if you do not see memcache listed in a ‘php -m’, you will need to add the module manually

First, you’ll want to very the location of your server’s extensions directory:

It should return something similar to the following:

Next, copy the memcache module into that directory (be sure to replace the path with the one found on your server):

Finally, add the module to your php.ini:


It used to be a common issue that the quick ‘install’ method could not be used for servers where the /tmp partition was mounted ‘noexec’. The problem was that the ‘configure’ process could not execute because the PECL client downloaded the module into in /tmp. When /tmp is mounted ‘noexec’, servers cannot execute scripts from /tmp.

However, PECL now downloads and executes the script from /root/tmp. No need to worry about compiler errors with /tmp. You can use the ‘install’ method even with a secured /tmp.

Note about this article

This article is one I had written for the ServInt blog as part of the ‘Tech bench’ series. You can view it on the ServInt blog here. They are using my article with my permission.

Jacob "Boom Shadow" Tirey

Posts Twitter

A linux web hosting administrator, a professional production sound man, and a renegade cop without nothing left to lose.... Ok, that last part is made up. In all seriousness, my passion in life is to help people; whether that be with help running their sites or with their productions. The name 'Boom Shadow' was given to me by a great group of filmmakers called Star Wipe Films. back in 2005 and has been with me since. I hope my site is helpful to you, and if there's something you need, drop me a line!