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
/etc/php.ini
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
/etc/php.d/
The actual php extensions are kept in
/usr/lib64/php/modules/
Install Memcached
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
For x86_64
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.
vi /etc/sysconfig/memcached
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
Start memcached
/etc/init.d/memcached start
Check it running
/etc/init.d/memcached status
or
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
Install Memcache PHP Extension
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
“configure: error: no acceptable C compiler found in $PATH”
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)
vi /etc/php.ini
Press
i
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
/etc/init.d/apache2 restart
Special Thanks
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/