William Jiang

JavaScript,PHP,Node,Perl,LAMP Web Developer – http://williamjxj.com; https://github.com/williamjxj?tab=repositories

CentOS 6.2: install memcached server and PHP memcache, memcached extensions

CentOS 6.2: install memcached server and PHP extensions

Here I summary the steps of installing memcached server and PHP memcached/memcache extension which are working on CentOS 6.2.

A. Install memcached server

A good reference is Here. memcached is a high-performance, distributed memory object caching system, generic in nature, but intended for use in speeding up dynamic web applications by alleviating database load. My steps are:

$ sudo rpm -Uvh http://mirrors.kernel.org/fedora-epel/6/x86_64/epel-release-6-7.noarch.rpm 
$ sudo yum install memcached
$ /etc/init.d/memcached start

3-steps to install memcached server and make it running, very simple.

B. install PHP memcache extension

The installation of PHP memcache extension is much easier than memcached extension. At this point, memcache extension is quicker solution. Just 1 step:

$  sudo pecl install memcache

C. install PHP memcached extension

It is a challenge to install PHP’s memcached extension. A good article is here for the installation. There are 2 pre-required packaged are needed:

  • libevent
  • libmemcached

(1) First we need to install libevent support libaray (http://libevent.org/)

$ wget https://github.com/downloads/libevent/libevent/libevent-2.0.20-stable.tar.gz
$ tar xzvf libevent-2.0.20-stable.tar.gz
$ cd libevent-2.0.20-stable
$ ./configure
$ make
$ sudo make install

(2) Second install libmemcached. I try to find the latest stable version of libmemcached which is used by PHP’s memcached.
$ wget https://launchpad.net/libmemcached/1.0/1.0.12/+download/libmemcached-1.0.12.tar.gz
$ tar xzvf libmemcached-1.0.12.tar.gz
$ cd libmemcached-1.0.12
$ ./configure && $ make && $ sudo make install
$ sudo pecl install memcached
The pecl will auto install memached latest version 2.1 into server. However it is *NOT* work, because libmemcached’s version(1.0.12) is not compatible with PHP memcached version(2.1)

(3) I googled and tried a lower version of libmemcached: Using 1.0.10 instead of 1.0.12

$ wget http://download.tangent.org/libmemcached-1.0.10.tar.gz
$ ./configure --with-memcached; make; sudo make install
// then:
$ sudo pecl install memcached

It works! So the key here is the version compatible of libevent, libmemcached, and PHP memcached.

C. Add in php.ini as extensions

After all the parts work fine, now adding them into php.ini to make they are the PHP extension which can be quickly shared.
$ sudo vi /etc/php.ini:



After the adding, restart httpd server to make it activiate:
$ sudo /etc/init.d/httpd restart
$ sudo /etc/init.d/memcached restart

By using phpinfo.php, or ‘pecl list’, we can see all memcached, memcache extensions are available.
By the way, PHP official site have complete documents for these wonderful cache systems.

  1. Memcache: http://www.php.net/manual/en/book.memcache.php
  2. Memcached: http://www.php.net/manual/en/book.memcached.php
  3. Mongo: http://www.php.net/manual/en/book.mongo.php

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: