Skip to main content

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 fromhttp://in2.php.net/manual/en/memcache.installation.php

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 http://www.monkey.org/~provos/libevent-1.4.8-stable.tar.gz
    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/libevent-1.4.so.2 /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 http://danga.com/memcached/dist/memcached-1.2.6.tar.gz
    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 127.0.0.1 -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 fromhttp://www.sitepoint.com/article/getting-started-with-pear/2/
  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 http://pear.php.net/go-pear -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 exportPATH=/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 ‘extension=memcache.so‘, 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.

Comments

Popular posts from this blog

Financial Engineering

Financial Engineering: Key Concepts Financial engineering is a multidisciplinary field that combines financial theory, mathematics, and computer science to design and develop innovative financial products and solutions. Here's an in-depth look at the key concepts you mentioned: 1. Statistical Analysis Statistical analysis is a crucial component of financial engineering. It involves using statistical techniques to analyze and interpret financial data, such as: Hypothesis testing : to validate assumptions about financial data Regression analysis : to model relationships between variables Time series analysis : to forecast future values based on historical data Probability distributions : to model and analyze risk Statistical analysis helps financial engineers to identify trends, patterns, and correlations in financial data, which informs decision-making and risk management. 2. Machine Learning Machine learning is a subset of artificial intelligence that involves training algorithms t...

Wholesale Customer Solution with Magento Commerce

The client want to have a shop where regular customers to be able to see products with their retail price, while Wholesale partners to see the prices with ? discount. The extra condition: retail and wholesale prices hasn’t mathematical dependency. So, a product could be $100 for retail and $50 for whole sale and another one could be $60 retail and $50 wholesale. And of course retail users should not be able to see wholesale prices at all. Basically, I will explain what I did step-by-step, but in order to understand what I mean, you should be familiar with the basics of Magento. 1. Creating two magento websites, stores and views (Magento meaning of website of course) It’s done from from System->Manage Stores. The result is: Website | Store | View ———————————————— Retail->Retail->Default Wholesale->Wholesale->Default Both sites using the same category/product tree 2. Setting the price scope in System->Configuration->Catalog->Catalog->Price set drop-down to...

How to Prepare for AI Driven Career

  Introduction We are all living in our "ChatGPT moment" now. It happened when I asked ChatGPT to plan a 10-day holiday in rural India. Within seconds, I had a detailed list of activities and places to explore. The speed and usefulness of the response left me stunned, and I realized instantly that life would never be the same again. ChatGPT felt like a bombshell—years of hype about Artificial Intelligence had finally materialized into something tangible and accessible. Suddenly, AI wasn’t just theoretical; it was writing limericks, crafting decent marketing content, and even generating code. The world is still adjusting to this rapid shift. We’re in the middle of a technological revolution—one so fast and transformative that it’s hard to fully comprehend. This revolution brings both exciting opportunities and inevitable challenges. On the one hand, AI is enabling remarkable breakthroughs. It can detect anomalies in MRI scans that even seasoned doctors might miss. It can trans...