Install Memcached on cPanel server

First of all install the libevent

wget http://downloads.sourceforge.net/project/levent/libevent/libevent-2.0/libevent-2.0.21-stable.tar.gz
tar zxvf  libevent-2.0.21-stable.tar.gz
cd libevent-2.0.21-stable
./configure
make
make install
cd ..

Then installed memcached

wget http://memcached.googlecode.com/files/memcached-1.4.15.tar.gz
tar zxvf memcached-1.4.15.tar.gz
cd memcached-1.4.15
./configure
make
make install
echo "/usr/local/lib/" > /etc/ld.so.conf.d/libevent-x86_64.conf

Now run the following commands

ldconfig
memcached -d -u nobody -m 1024 127.0.0.1 -p 11211

Now install the memcached

wget https://launchpad.net/libmemcached/1.0/1.0.17/+download/libmemcached-1.0.17.tar.gz
tar zxvf libmemcached-1.0.17.tar.gz
cd libmemcached-1.0.17
make && make install
./configure
make && make install

Then run the following to check if memcached.so is installed into /usr/local/lib/php.ini file and add it if is it not:

grep -q "memcached.so" /usr/local/lib/php.ini || echo 'extension=memcached.so' >> /usr/local/lib/php.ini

You can check the extension directory you are using and whether it is in it using this line:

for i in `grep ^extension_dir /usr/local/lib/php.ini | awk {'print $3'} | cut -d\" -f2` ;do ls -lah $i/memcache* ;done

Also, to preserve the memcached.so module on EasyApache recompiles, this needs to be done as well:

for i in `grep ^extension_dir /usr/local/lib/php.ini | awk {'print $3'} | cut -d\" -f2` ;do cp $i/memcached.so /root ;done
for i in `grep ^extension_dir /usr/local/lib/php.ini | awk {'print $3'} | cut -d\" -f2` ;do echo -e '#!/bin/bash\ncp /root/memcached.so' "$i\ngrep -q 'memcached.so' /usr/local/lib/php.ini || echo 'extension=memcached.so' >> /usr/local/lib/php.ini\n/etc/init.d/httpd restart" > /usr/local/cpanel/scripts/posteasyapache ;done
chmod +x /usr/local/cpanel/scripts/posteasyapache

This will create a posteasyapache script that will ensure memcached.so is copied from /root/memcached.so back into the php extension directory.

I followed the above details, and it shows up installed onto my machine:

root@host [~]# php -i | grep -i memcached
memcached
memcached support => enabled
libmemcached version => 1.0.4
Registered save handlers => files user sqlite memcached

About 

Sreejit is the founder of Server Management Plus. His motto is "If there's an easier way, Why do it any other way" and following it, he has created a lots of automation scripts for the company using which we are able to resolve issue at an extremely fast rate and save lots of time. He has a very keen interest in new technologies and spend most of his free time online researching about it apart from listening music and watching movies.

1 thought on “Install Memcached on cPanel server”

  1. Pingback: Cpanel Memcached – SH Xiang Gelila

Comments are closed.