Memcache (Data + Object caching)

Memcache(d) is a object caching system that stores data in RAM to reduce the number of times something has to be read. It is generally used to speed up dynamic database-driven websites.

Quick Links:
Memcache repo CentOS
Installing memcache
Installing memcache php module
Php.ini configuration
Memcache Commands


First thing to do is make sure you have the correct repository installed with:

rpm -Uvh


To install memcache you can use the following:

yum install -y memcached

and then turn it on from server boot:

chkconfig memcached on

Now we need to make some configuration changes by editing /etc/sysconfig/memcached and you should see something similar to:






You should then update the options section to:


Php module

You will now need to install the php module.

yum groupinstall “Development Tools”

yum install zlib-devel libmemcached-devel php-pear php-pecl-memcached

pecl install -f memcached-1.0.0

Php.ini config

Once you have done this you will need to edit your php.ini file found at /etc/php.ini

You should then locate the following section:


; Handler used to store/retrieve data.


session.save_handler = files

You should change this section to the following:


; Handler used to store/retrieve data.


session.save_handler = memcached

session.save_path = ""


Restart apacheĀ  and your done!

You may get a message when restarting apache similar to:

Starting httpd: httpd: apr_sockaddr_info_get() failed for memcached

httpd: Could not reliably determine the server's fully qualified domain name, using for ServerName

This can be resolved by editing /etc/httpd/conf/httpd.conf and commenting or adding the following line

ServerName localhost

Restart apache to resolve this issue.

Memcache commands

Is memcache running?

If you log into your server as a user (not root) and run the following command it will tell you what is being cached by memcache

memcached -vv