How to install MemCached in Ubuntu

Posted on Friday June 24, 2011 / by Eric Potvin

What is MemCached?

"MemCached is a high-performance, distributed memory object caching system, generic in nature, but originally intended for use in speeding up dynamic web applications by alleviating database load."

Basically, it means it save and retrieve data in the server memory. This is typically used to remove the loads on the database server.

The logic of MemCached is very simple:

run the following command to install memcached:

sudo aptitude install memcached

If you want to change the default settings, simply create the file and update the configuration.

First, create memcached configuration file:

vi /etc/memcached.conf

Then, change the settings:

# Memory a usage in Mb
-m 16
# default port
-p 11211
# user to run daemon nobody/apache/www-data or else
-u nobody
# only listen locally
-l 127.0.0.1

Save and quit the file. Once this is complete, don't forget to restart the daemon:

sudo /etc/init.d/memcached restart

Now lets install for php

sudo aptitude install php5-memcached

Restart both services:

sudo /etc/init.d/memcached restart ; sudo /etc/init.d/apache2 restart

If you would like additional information about MemCached please visit: http://memcached.org/