How to install memcached into CPanel running CentOS

Without wasting much time,To install and use memcached caching in any software, we need to do following three steps.

  1. Install libevent library that is used by memcached server
  2. Install memcached server and start it
  3. 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
tar zxvf libevent-1.4.14b-stable.tar.gz
cd libevent-1.4.14b-stable
make install

Install Memcached server on CentOS

Now, install the memcache and get the latest version from their site.

tar -zxvf libmemcached-1.0.4.tar.gz
cd libmemcached-1.0.4
make && make install
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