Step By Step Guide To Install Memcache On Linux

This post is more like a note to me, so that in future I can look up for steps involved in installing memcache on Linux servers like Centos or RHEL.

Those of you who follow me on twitter, will know that me and my friends spends hours trying to install memcache on one of our web server. Normally this is a five minute job, but unfortunately for us those tricks did not work out.

So if you have tried YUM and APT-GET and still could not install the memcache then read on, to find the alternate( read manual, without magic ) way of doing it.

When we talk about Memcache their two things that needs to be installed

  1. Memcache Daemon know as memcached, and
  2. Memcache client for your programing language, in this case PHP.

Installing Memcache Daemon

Note these steps has been taken from

Steps to install Libevent(memcached dependency)

  1. First we need to check if libevent is installed or not?
    1. type whereis libevent on shell.
  2. If you don’t find it, then we need to download and install it.  Type following sequence of commands on your shell
    1. wget
    2. tar xfz libevent-1.4.8-stable.tar.gz
    3. cd libevent-1.4.8-stable
    4. ./configure
    5. make
    6. sudo make install
  3. Finally we need to create a symlink to libevent
    1. type  sudo ln -s /usr/local/lib/ /usr/lib on shell.

Now that we have installed the dependencies, we will install the memcahced.

Steps to install Memcached

  1. Download and install, for that type following sequence of commands on your shell
    1. wget
    2. tar xfz memcached-1.2.6.tar.gz
    3. cd memcached-1.2.6
    4. ./configure
    5. make
    6. sudo make install
  2. Run Memcached as a daemon (d = daemon, m = memory, u = user, l = IP to listen to, p = port)
    1. type memcached -d -m 1024 -u root -l -p 11211 on shell

Note: versions numbers mentioned here might be outdated, so do check for updated package to download.

Now we have installed and started the Memcache daemon, it’s time to install PHP client.

Installing Memcache Extension for PHP

Some of the steps mentioned below are taken from

  1. Let’s determine the PHP version installed and also make sure it is in system path.
    1. type php -v on you shell, it should show something like PHP 5.2.6 (cli) (built: Nov  4 2008 09:25:57)
    2. type whereis php to get the path where PHP is installed in your system.
    3. In your accounts home directory create/edit ‘.profile’ file and add ‘export PATH=$PATH:/usr/local/bin‘ where ‘/usr/local/bin‘ is the folder where php executable is installed.
  2. Install PEAR, type following sequence of commands on your shell
    1. wget -O go-pear.php
    2. php go-pear.php and follow the installation instructions
    3. ls -l ~/.pearrc
    4. edit the ‘.profile‘ (again) and add export PATH=/home/yourname/pear/bin:$PATH
  3. Finally Install Memcache
    1. type pecl install memcache on your shell, it will install memcahce extension for PHP.
  4. Edit php.ini to add ‘‘, to find the exact php.ini file used by your system
    1. php -i | grep ‘php.ini’
  5. Restart apache, and you are done  type one of the commands below to do that
    1. /etc/init.d/apache  restart , or
    2. service httpd restart

I hope this helps and save some time for you, I have a limited knowledge of Linux, so if some one can improve in the steps, please do so in the comments.

16 thoughts on “Step By Step Guide To Install Memcache On Linux

  1. Hello I am Ranjith kumar working as a civil Engg in Sobha Developers, first off all i would like to thank u for ur research on how to manually remove virus procedures. I was dieing with this go damn viruses but at last i found the real place to get the solutions. So i request u 2 advertise ur site ur site so that more & more people can know ur site. i would also be happy i would get mails regarding ur research on manual removal of virus
    or u can start a group to help ur research,i would be happy to join eventhough i dont know much as u.
    Thank u once again for ur helpfull link.

  2. I am trying to use your guide above to install memcache, and I am on one of the last steps, but am getting an error.

    When I run this command:
    pecl install memcache

    I get this error:
    downloading memcache-2.2.5.tgz …
    Starting to download memcache-2.2.5.tgz (35,981 bytes)
    ……….done: 35,981 bytes
    11 source files, building
    running: phpize
    sh: phpize: command not found
    ERROR: `phpize’ failed

    I read that this is an old php bug, but I don’t know how to work around it.

  3. Hi Amit,

    First, thank you again for posting this info, and for your help.

    I got memcached going just fine on my server by following your directions above, however, I am having two issues:

    1) Whenever a php command is run on my ssh command line (and possibly via other means), I get this error:
    “PHP Warning: Module ‘memcache’ already loaded in Unknown on line 0”
    Could this be caused by the line I put into the php.ini file to run memcached, and if so, do I need that line in there?

    2) When my server restarts memcached does not run, even though I successfully followed all steps above. The only way I can get it started again is via this step:
    type memcached -d -m 1024 -u root -l -p 11211 on shell
    What is my best solution for this issue…should I create a cron that runs every 15 minutes or so with that command, or is there a better way to handle this problem?

    Thank you,

  4. @Scott – The error you are seeing says that you already included in your php.ini and now it shows up in there twice.
    Check your php.ini and remove the duplicate ‘’


  5. Hi Amit,

    Thank you for your post it has helped immensely!

    I am slightly stuck though, when it comes to step 4;

    Edit php.ini to add ‘‘, to find the exact php.ini file used by your system

    should the extension entry already be in this file?

    thank you again


  6. Pingback: is now open sourced! - 72Lions - The playground of developer Thodoris Tsiridis

  7. Hello Amit,

    First thank you for this again, and for past help. I used your instructions above to install memcached-1.4.X on my server, and now I need to upgrade it to the next version. I know I need to:
    1) go into the directory of the old version and type “make uninstall”
    2) download, inpack and install the new one.

    Will I need to go through all the steps above, including updating the symbolic links, etc?

  8. HI Amit

    We are installing a new application called checkbox in windows servers 2008 on IIS 6.0. We are facing some issue with Memcache ,
    We don’t have an idea about memcache where to install it , it should install on Application server or Database server. Please assist.

    Thanks you.

  9. Thanks for the post. Its very helpful.
    I am facing some problem in connection. I am getting following error
    java.util.concurrent.TimeoutException: Operation timeout
    at net.rubyeye.xmemcached.XMemcachedClient.getKeyIterator(

    I am trying to connect a client from client machin to Memcached Server on UNIX BOX.
    Memcached is working fine with application but outside app client is givning this error .

    I used following command to start the memcached server
    /opt/memcached/bin/memcached -u nobody-d -m 1024 -p 11211 -l

  10. Hi, when i install PEAR in second step ( php go-pear.php ) i get the message in my screen “Sorry! Your PHP version is too new (5.4.31) for this go-pear.
    Instead use for a more stable and current
    version of go-pear, more suited to your PHP version.”

Comments are closed.