Install Memcache on CentOS 6 cPanel

Here is how to install Memcache for PHP on a CentOS 6 cPanel / WHM box. Some of the guides suggest that you need libevent (well, you do need libevent), though when I tried it, I already had it installed. But if you need it, yum will sort you out.

yum install libevent

Next, install memcache itself. Note that the package is called memcached.

yum install memcached

Of course, just installing it doesn’t mean that the daemon is running. So don’t forget to start it too!

/etc/init.d/memcached start

Finally, we need to add the PHP extension. Beware that the PECL installer on WHM won’t work! So you need to compile it manually from source. That isn’t too difficult though.

wget http://pecl.php.net/get/memcache
tar zxvf memcache
cd memcache-3.0.6
phpize
./configure
make
make install

And add the extension to your php.ini.

extension=memcache.so

Now restart Apache and a memcache section should appear in your PHP info.

Install memcached on CentOS 5

First step, you’ll need to add the EPEL repository to Yum.

Once you’ve done that, you can install all the YUM packages.

yum -y install memcached.x86_64 libmemcache.x86_64 libmemcache-devel.x86_64 zlib-devel.x86_64

Then add the memcache extension to PHP.

pecl install memcache

Add the extension to your PHP configuration.

extension=memcache.so

Configure memcached appropriately.

vi /etc/sysconfig/memcached
add OPTIONS="-l 127.0.0.1"

Configure it as a service, and start.

chkconfig memcached on
service memcached start