Install memcached php extension CentOS 5 and 6

Speed check using hping3 when ICMP packets are disabled

Install memcached php extension

Ok, I recently explained how to install memcached on Centos 5 and 6, now we need to install the memcached php extension to use it in your php web applications.

There are two ways to do this, using Pecl or manually compiling it. I’ll explain both ways here and I’ll start right off with Pecl as its the easiest one.

  • Install using Pecl

Make sure you first have Pecl installed, if not, you just need to install php-pear and php-devel, both are needed for this.

Then run the command:

pecl install memcached

This will install memcache extension and you just need to make sure that your php ini contains:

extension = "memcache.so"

Then restart the web server to load php extension again:

/etc/init.d/httpd restart

And that’s it!

  • Installing manually

There are times when Pecl will not work, probably due to /tmp/ direct doesn’t have enough permission to compile the extension.

In any case, when the automatic install doesn’t work, install manually:

cd /usr/src
wget http://pecl.php.net/get/memcache-2.2.5.tgz
tar zxvf memcache-2.2.5.tgz
cd memcache-2.2.5
phpize
./configure
make
make install

The memcache.so module will be installed in the php module folder, then enable it by adding the line to your php.ini file:

extension = "memcache.so"

To make sure you’re using the correct php.ini file you can run the command:

php -i | grep php.ini
Configuration File (php.ini) Path => /usr/local/lib
Loaded Configuration File => /usr/local/lib/php.ini

Then restart the web server to load php extension again:

/etc/init.d/httpd restart

And memcached extension is now installed!

Unauthorized use and/or duplication of this material without express and written permission from this blog’s author and/or owner is strictly prohibited. Excerpts and links may be used, provided that full and clear credit is given to www.yourhowto.net with appropriate and specific direction to the original content.