Without wasting much time,To install and use memcached caching in any software, we need to do following three steps.
- Install libevent library that is used by memcached server
- Install memcached server and start it
- Install PHP extension for memcache
Before installing memcached server, just create a directory at any location that you want to use as command below.
mkdir ~/memcache
Installing libevent on CentOS
Run following commands to install libevent on CentOS. Use the latest libevent stable version.
cd ~/memcache wget http://monkey.org/~provos/libevent-1.4.14b-stable.tar.gz tar zxvf libevent-1.4.14b-stable.tar.gz cd libevent-1.4.14b-stable ./configure make make install
Install Memcached server on CentOS
Now, install the memcache and get the latest version from their site.
wget http://launchpad.net/libmemcached/1.0/1.0.4/+download/libmemcached-1.0.4.tar.gz tar -zxvf libmemcached-1.0.4.tar.gz cd libmemcached-1.0.4 ./configure make && make install OR yum install memcached
The install php memcache
pecl install memcache
Make sure memcache module is present in php.ini file. If not, you can add the memcache extension in php.ini file.
cat /usr/local/lib/php.ini | grep memcache
Restart the Apache services.
service httpd restart
Make sure memcached will remain even after a server reboot:
# chkconfig --levels 235 memcached on
Finally to check if memcache is installed or not?
php -m | grep memcache memcache