The following post is a tutorial on how to install memcached and memcache php extension on Centos 5. Before you start there are a few useful points that might come in handing if you come across any errors.
php.ini file is kept in
To find out where your php.ini file is kept you can type the following command
php -i | grep php.ini
The default extensions loaded are kept in this folder
The actual php extensions are kept in
Enable the following repository.
For i386 / i686
rpm -Uhv http://apt.sw.be/redhat/el5/en/i386/rpmforge/RPMS/rpmforge-release-0.3.6-1.el5.rf.i386.rpm
rpm -Uhv http://apt.sw.be/redhat/el5/en/x86_64/rpmforge/RPMS//rpmforge-release-0.3.6-1.el5.rf.x86_64.rpm
Use the command Yum to install memcached
yum -y install memcached
If no error popup then you have successfully installed memcache. You should then configure memcache by typing the following command.
you should see:
PORT="11211" #define on which port to urn USER="nobody" #same as apache user MAXCONN="1024" #maximum number of connections allowed CACHESIZE="64" #memory used for caching OPTIONS="" #use for any custom options
Check it running
netstat -anp | grep 11211
To stop / restart memcache
service memcached stop service memcached restart
To See Memory Memcached Slabs
memcached-tool IP_ADDRESS:Port memcached-tool IP_ADDRESS:Port display memcached-tool 127.0.0.1:11211
To See Memory Memcached Stats
memcached-tool IP_Address:Port stats memcached-tool 127.0.0.1:11211 stats
Download and install lastest memcache version.
cd /usr/src wget http://pecl.php.net/get/memcache-2.2.5.tgz tar zxvf memcache-2.2.5.tgz cd memcache-2.2.5 phpize ./configure make make install
If for some reason the above code errors saying something like you do not have a compiler installed run the following command.
yum install gcc
Add memcache extension to php.ini file (depending on your version of PHP you may not need this step)
Scroll don until you see a large block of code saying extension = …. Then add the following
extension = "memcache.so"
To check memcache is correctly installed with php
php -i | grep memcache
Finally Restart Apache
This post would not have been possible without the follow tutorials and articles. I highly recommend you check them out as they list different techniques and include other information like how to start memcache as a service.
http://www.cyberciti.biz/faq/rhel-fedora-linux-install-memcached-caching-system-rpm/ http://codelikezell.com/how-to-install-memcached-on-centos/ http://www.lullabot.com/articles/installing-memcached-redhat-or-centos http://www.sohailriaz.com/how-to-install-memcached-with-memcache-php-extension-on-centos-5x/