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
Show 1 Comment

1 Comment

Comments are closed