One of the dependencies of memcache is libevent, so firstly download the source files for Libevent.
wget http://www.monkey.org/~provos/libevent-1.3b.tar.gz
tar -xvf libevent-1.3b.tar.gz
cd libevent-1.3b
./configure;make;make install;
Download the latest Memcached source code from danga.com
wget http://danga.com/memcached/dist/memcached-1.2.1.tar.gz
gunzip memcached-1.2.1.tar.gz
tar -xvf memcached-1.2.1.tar
cd memcached-1.2.1
./configure;make;make install;
Often libevent.so cannot be found when executing memcache. A useful command LD_DEBUG, is very helpful to determine where libraries are being loaded from.
LD_DEBUG=help memcached -v
LD_DEBUG=libs memcached -v 2>&1 > /dev/null | less
18990: find library=libevent-1.3b.so.1 [0]; searching
…
18990: trying file=/usr/lib/libevent-1.3b.so.1
18990:
memcached: error while loading shared libraries: libevent-1.3b.so.1: cannot open shared object file: No such file or directory
Simply place the library where memcached will find it and execute memcached.
ln -s /usr/local/lib/libevent-1.3b.so.1 /lib/libevent-1.3b.so.1
memcached -d -u nobody -m 512 127.0.0.1 -p 11211
To install the pecl package for PHP
wget http://pecl.php.net/get/memcache-2.1.2.tgz
gzip -df memcache-2.1.2.tgz
tar -xvf memcache-2.1.2.tar
cd memcache-2.1.2
phpize
./configure;make;make install;
Add memcache.so to the php.ini file
extension=memcache.so
Then run
php -i | grep -i ‘memcache’
memcache should be listed and then restart the web server.
Thats all 🙂