How to install Memcached on CentOS (with DirectAdmin installed) + Memcached PECL

By BXTra |

After I was done with install Memcached on CentOS a while ago, I just know today that there are 2 different PECL modules. One is "Memcache PECL" while another is "Memcached PECL". The one I did before is "Memcache PECL", so, now, I try to install "Memcached PECL" which is newer and require libmemcached library.

The content below is almost exactly to my previous Memcache PECL installed. Only a few changes to install Memcached PECL instead.

Get Libevent which is require to install Memcached. Their homepage is here -> http://www.monkey.org/~provos/libevent/

wget http://www.monkey.org/~provos/libevent-1.4.13-stable.tar.gz
tar -xvf libevent-1.4.13-stable.tar.gz
cd libevent-1.4.13-stable
./configure;make;make install;

Then, get Memcached from http://memcached.org

wget http://memcached.googlecode.com/files/memcached-1.4.5.tar.gz
gunzip memcached-1.4.5.tar.gz
tar -xvf memcached-1.4.5.tar
cd memcached-1.4.5
./configure;make;make install;

For me, I got an error below :

error while loading shared libraries: libevent-1.4.so.2: cannot open shared object file: No such file or directory

So, I did steps below :

nano /etc/ld.so.conf.d/libevent-i386.conf

Then, enter into the textbox

/usr/local/lib/

Then, CTRL+O to save, CTRL+X to exit.

Then, run

 ldconfig

Once you're done with that, try run

memcached -d -u nobody -m 1024 127.0.0.1 -p 11211

This is not done yet, you need to let PHP knows to be able to use memcached.

wget http://launchpad.net/libmemcached/1.0/0.40/+download/libmemcached-0.40.tar.gz
tar -zxvf libmemcached-0.40.tar.gz
cd libmemcached-0.40
./configure

You will see screen below :

Then, run

make && make install

Then install Memcached PECL with below command :

pecl install memcached

Once it's done, you will see the screen below:

With above picture, you may notice that the extension path is different to what we normally see. The path in the picture say :

/usr/local/php5/lib/php/extensions/no-debug-non-zts-20060613

But what most module for PHP 5.2 installed will compile into

/usr/local/lib/php/extensions/no-debug-non-zts-20060613

Therefore, make sure you get the right path for extension_dir Edit php.ini to have lines below : (Make sure the line "extension_dir" is there or you need a full path to memcached.so )

extension_dir = "/usr/local/lib/php/extensions/no-debug-non-zts-20060613"
extension=memcached.so

Then, restart HTTP and check PHP Status.. You will see Memcached info as below:

In case you need to use Memcached as a session handler. (Not require) Then, you need to edit php.ini and set variable below :

session.save_handler=memcached
session.save_path="127.0.0.1:11211"

Now, you're done install Memcached on the server. However, you need to modify some code in your website script to make use of Memcached.

 

Server Information - Software - CentOS 5.4
- DirectAdmin 1.351
- Apache 2.2.15
- PHP 5.2.13
- MySQL 5.1.45

Source : - http://blog.ajohnstone.com/archives/installing-memcached/
- http://alexle.net/archives/275
- http://hasin.wordpress.com/2009/10/18/using-new-pecl-memcached-extension-for-storing-session-data

clients/ms_thread.o:/home/dcardin/build/libmemcached-0.37/clients/ms_thread.c:198: more undefined references to `__sync_fetch_and_add_4′ follow see: http://redbeardtechnologies.wordpress.com/2010/01/26/libmemcached-undefined-reference-to-__sync_fetch_and_add_4/

Add new comment

  • No HTML tags allowed.
  • Web page addresses and email addresses turn into links automatically.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.