Friday, August 22, 2008

Configure Memcached server with Linux


Memcached is a distributed caching tool developed by Danga. It can be used to speed up web by caching heavy objects in the memory and by reducing the database round trips. Memcached configuration is very straight forward.


It needs an additional component to be installed on your linux box, libevent. You can install libevent from source or from yum. Installing through yum is easy. All you need to type is yum install libevent. If you want to install libevent from the source follow these steps.

1) Download the latest version of libevent from their web site and unzip the tar ball(tar.gz) to a folder (ex-/home/your-username/

2) Go to the terminal and login as root (it is not necessary to login as root but on some distributions permission issues might arise. Better safe than sorry ;) ) by typing su or sudo depending on your distribution

3) Install libevent
# ./configure –prefix=/usr/local
# make install
When we configure libevent we tell the compiler to configure it to /usr/local where all the library files are kept

4) Download memcached from the site and unzip to a folder. Now we are ready to install memcached.
# ./configure –with-lib-event=/usr/local/
# make install
We tell the compiler to compile memcached with libevent which is located at usr/local directory. If all goes well memcached is ready to go

5) Type memcached on the terminal then you see the service is running. Or else type memcached -vv to rjavascript:void(0)un memcached in the very verbose mode which is quite helpful at the beginning to debug.

6) If you want to use memcached with php then you need to install PECL extension for PHP. This can be done by typing yum install php-pecl-memcached in the command line.

7) Have a php info page and you will see a section called Memcached if all goes well. :)