Memcache module provides handy procedural and object oriented interface to memcached, highly effective caching daemon, which was especially designed to decrease database load in dynamic web applications.
Login to Linux Server using root credentials. Use PuTTY/KiTTY to login.
Download and Install LibEvent
First make a folder named memcache to download the required setup files:
# mkdir memcache (make directory memcache)
# cd memcache (go to memcache directory)
Memcache requires LibEvent. Go to their site and get the latest version.
http://www.monkey.org/~provos/libevent-1.4.13-stable.tar.gz (Latest stable version)
OR
http://ftp.redhat.com/pub/redhat/rhel/beta/6/x86_64/os/Packages/libevent-1.4.13-1.el6.x86_64.rpm
# wget http://www.monkey.org/~provos/libevent-1.4.13-stable.tar.gz (download libevent latest stable version)
# tar xvfz libevent-1.4.13-stable.tar.gz (Unzip the zip file)
# cd libevent-1.4.13-stable (go to unzipped directory)
# ./configure (Configure)
# make (Compile the file to prepare for installation)
# make install (Run install process)
# cd
[To check if installed or not]
#whereis libevent
[Success will be shown with package path otherwise blank]
[To find certain package]
#find / -name libevent-1.4.13-stable
[List files]
#ls
Download and Install Memcached
Now you can install Memcache. Again you should check their site for the latest version.
http://memcached.googlecode.com/files/memcached-1.4.4.tar.gz (Take the latest version)
[Added later:
http://memcached.googlecode.com/files/memcached-1.4.5.tar.gz as on June 2010 ]
# wget http://memcached.googlecode.com/files/memcached-1.4.4.tar.gz
# tar xvfz memcached-1.4.4.tar.gz
# cd memcached-1.4.4
# ./configure
# make
# make install
Starting Memcache
Run memcache as daemon (service start) [ Syntax: memcached -d -u [user] -m [memory size] -p [port] [listening IP] ] # memcached –d –m 1024 –u root –l 127.0.0.1 –p 11211
Try starting memcache.
memcached
If you get the following error then you may need to register libevent:
error while loading shared libraries: libevent-1.4.so.2: cannot open shared object file: No such file or directory
Register LibEvent
vi /etc/ld.so.conf.d/libevent-i386.conf
[Press i to insert]
–[paste]–
/usr/local/lib/
[Save and exit: Press Esc -> Shift+; -> wq ->Enter ]
#ldconfig
Install zlib package
# wget http://www.zlib.net/zlib-1.2.5.tar.gz ( Go to http://www.zlib.net/ and take the latest version) # tar xvfz zlib-1.2.5.tar.gz # cd zlib-1.2.5 # ./configure # make # make install
Installing PHP Memcache
Install the PHP Memcache extension.
http://pecl.php.net/get/memcache-2.2.5.tgz
wget http://pecl.php.net/get/memcache-2.2.5.tgz
tar xvfz memcache-2.2.5.tgz
cd memcache-2.2.5
phpize (phpize:Command not found case, run yum install php-devel then YES)
Again
phpize (Now it should work with no error )
./configure –enable-memcache
make
make install
# cp modules/memcache.so /usr/lib64/php/modules/
[Path can be : /usr/lib/php/modules/]
# vi /etc/php.d/memcached.ini
–paste–
extension=memcache.so
( See the phpinfo() and take path Loaded Configuration File )
[ The path of php.ini file varies with hosting provider. For ukfast.co.uk server, /etc/php.ini ]
vi /usr/local/lib/php.ini
–[paste]–
extension=memcache.so
–[/paste]—
#service httpd restart
Or
# /etc/init.d/network restart
After Setup: Include the following code in the top of the index page.
if(substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], ‘gzip’)) ob_start(“ob_gzhandler”); else ob_start();
$memcache = new Memcache;
$memcache->connect(“localhost”,11211);

Posted in
Tags: 








Thanks a bunch!
New article too written last month.. So everything worked wonderful.
(There is ton of ‘old’ tutorials on the web for this that dont work.)
I followed the same procedure but it’s not working for me. I am getting the below warning -
PHP Warning: PHP Startup: memcache: Unable to initialize module
Module compiled with module API=20050922, debug=0, thread-safety=0
PHP compiled with module API=20060613, debug=0, thread-safety=0
These options need to match
in Unknown on line 0
PHP Warning: PHP Startup: memcache: Unable to initialize module
Module compiled with module API=20050922, debug=0, thread-safety=0
PHP compiled with module API=20060613, debug=0, thread-safety=0
These options need to match
in Unknown on line 0
PHP 5.2.14 (cli) (built: Jul 25 2010 12:10:48)
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2010 Zend Technologies
with Xdebug v2.1.2, Copyright (c) 2002-2011, by Derick Rethans
Is there any way to get rid of it ?