Install memcached php extension CentOS 5 and 6
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:
1 |
pecl install memcached |
This will install memcache extension and you just need to make sure that your php ini contains:
1 |
extension = "memcache.so" |
Then restart the web server to load php extension again:
1 |
/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:
1 2 3 4 5 6 7 8 |
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:
1 |
extension = "memcache.so" |
To make sure you’re using the correct php.ini file you can run the command:
1 2 3 |
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:
1 |
/etc/init.d/httpd restart |
And memcached extension is now installed!