Install Memcached on cPanel server

First of all install the libevent

tar zxvf  libevent-2.0.21-stable.tar.gz
cd libevent-2.0.21-stable
make install
cd ..

Then installed memcached

tar zxvf memcached-1.4.15.tar.gz
cd memcached-1.4.15
make install
echo "/usr/local/lib/" > /etc/

Now run the following commands

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

Now install the memcached

tar zxvf libmemcached-1.0.17.tar.gz
cd libmemcached-1.0.17
make && make install
make && make install

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

grep -q "" /usr/local/lib/php.ini || echo '' >> /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 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/ /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/' "$i\ngrep -q '' /usr/local/lib/php.ini || echo '' >> /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 is copied from /root/ 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 support => enabled
libmemcached version => 1.0.4
Registered save handlers => files user sqlite memcached


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.