Memcached is much much useful if your site is a heavy traffic site or you are feeling too many mysql hikes on your server. relax your server by installing the memcached and let it handle some of your burden by caching the most used pages, posts and even your tables etc.

Installation of this useful application is very easy.

just follow the steps below and you are done. In case you are stuck in some trouble please lemme know and I will try to resolve your problem asap. (depending on the time availability)

The easiest way is through the package manager.

sudo yum install memcached

If yum couldn’t find the repository to install the memcached then do the following steps to install the add the repository first.

1 ) Find out the release and version of your OS

cat /etc/redhat-releases

CentOS release 5.0 (Final)

uname -a

Linux domU-12-31-39-06-BC-E2 2.6.16-xenU #1 SMP Mon May 28 03:41:49 SAST 2007 i686 i686 i386 GNU/Linux

2) Install the RPM server that matches your architecture and CentOS version from http://dag.wieers.com/rpm/FAQ.php#B2

3) Use rpm command to add the repository

rpm -Uhv http://apt.sw.be/redhat/el5/en/i386/rpmforge/RPMS/rpmforge-release-0.3.6-1.el5.rf.i386.rpm

In my case, the url is as mentioned in the command

4) Now try out the yum command and you should be able to make it through :)

yum install memcached

5) To check out the installation by typing

memcached -h

It will display the help of memcached and on the first line will show the version …

memcached is installed. Now proceed with the PECL extension for PHP

6) Install through pecl install

pecl install memcache

at the end of installation it will display

You should add “extension=memcache.so” to php.ini

7) ok, So add the line to php.ini

you can use whatever editor you like, I use “vi”

sudo vi /etc/php.ini

8) after copying the line in the php.ini.. simply restart the apache server

sudo /etc/init.d/httpd restart

9) Till now, we have successfully installed memcached and added its extension in php.ini but haven’t yet started it. So to start it as a service.

use this file (thanks to lullabot.com)

#!/bin/sh
#
# memcached    Startup script for memcached processes
#
# chkconfig: - 90 10
# description: Memcache provides fast memory based storage.
# processname: memcached

# These mappings correspond one-to-one with Drupal's settings.php file.

[ -f memcached ] || exit 0

prog="memcached"

start() {
    echo -n $"Starting $prog "
    # Sessions cache.
    memcached -m 16 -l 0.0.0.0 -p 11211 -d -u nobody
    # Default cache.
    memcached -m 32 -l 0.0.0.0 -p 11212 -d -u nobody
    # Block cache.
    memcached -m 32 -l 0.0.0.0 -p 11213 -d -u nobody
    # Content cache. Holds fully loaded content type structures.
    memcached -m 16 -l 0.0.0.0 -p 11214 -d -u nobody
    # Filter cache. Usually the busiest cache after the default.
    memcached -m 32 -l 0.0.0.0 -p 11215 -d -u nobody
    # Form cache.
    memcached -m 32 -l 0.0.0.0 -p 11216 -d -u nobody
    # Menu cache.
    memcached -m 32 -l 0.0.0.0 -p 11217 -d -u nobody
    # Page cache. Bigger than most other caches.
    memcached -m 128 -l 0.0.0.0 -p 11218 -d -u nobody
    # Views definition cache.
    memcached -m 1 -l 0.0.0.0 -p 11219 -d -u nobody
    # Views data cache (may need to be increased if heavily used).
    memcached -m 32 -l 0.0.0.0 -p 11220 -d -u nobody

    # More caches that might be added later:

    # Users table.
    #/usr/bin/memcached -m 24 -l 0.0.0.0 -p 11219 -d -u nobody
    # Path source cache.
    #/usr/bin/memcached -m 4 -l 0.0.0.0 -p 11220 -d -u nobody
    # Path destination cache.
    #/usr/bin/memcached -m 6 -l 0.0.0.0 -p 11221 -d -u nobody
    RETVAL=$?
    echo
    return $RETVAL
}

stop() {
    if test "x`pidof memcached`" != x; then
        echo -n $"Stopping $prog "
        killall memcached
        echo
    fi
    RETVAL=$?
    return $RETVAL
}

case "$1" in
        start)
            start
            ;;

        stop)
            stop
            ;;

        restart)
            stop
            start
            ;;
        condrestart)
            if test "x`pidof memcached`" != x; then
                stop
                start
            fi
            ;;

        *)
            echo $"Usage: $0 {start|stop|restart|condrestart}"
            exit 1

esac

exit $RETVAL

load this in /etc/init.d/memcached

chmod 755 /etc/init.d/memcached

service memcached start

if you want to add it to server startup then use

chkconfig –add memcached

———-

done (y)