Installing The PHP-MemCache Module On CentOS 5.0

Want to support HowtoForge? Become a subscriber!
 
Submitted by thim (Contact Author) (Forums) on Mon, 2007-07-16 17:30. :: CentOS | PHP

Installing The PHP-MemCache Module On CentOS 5.0

Author & Content by Tim Haselaars (http://www.trinix.be)

“MemCached” is a high-performance, distributed memory object caching system, generic in nature, but intended for use in speeding up dynamic web applications by alleviating database load.

In this howto I explain how you can very easily install it and make it avaible in PHP. 

You need to activate the RPMForge custom repository (formely known as Dag Wieers): http://dag.wieers.com/rpm/packages/rpmforge-release/

Grab your specific RPM and install it:

wget http://dag.wieers.com/rpm/packages/rpmforge-release/rpmforge-release-*.rpm
rpm --install rpmforge-release-*.rpm

yum install --enablerepo=rpmforge memcached

Now memcached is installed.

You can test it:

memcached -m 512 -u nobody -vv

First, you start up the memcached daemon on as many spare machines as you have. The daemon has no configuration file, just a few command line options, only 3 or 4 of which you'll likely use:

./memcached -d -m 2048 -l 10.0.0.40 -p 11211 -u nobody

This starts memcached up as a daemon, using 2GB of memory, and listening on IP 10.0.0.40, port 11211. The -m switch specifies the amount of memory in megabytes. The -l switch specifies the IP to listen on and finally the -p switch specifies the port to listen on. The default port is 11211 and if your machine has just 1 IP you can omit the -l parameter. In the above example I set the amount of memory to 2GB. Of course you should use a sensible amount of memory. Making your machine swap to disk sort of defeats the purpose of a memory cache daemon. Note that it's perfectly fine to run the memcached daemon on another machine than the one you're running your actual PHP project on. You could even set up a machine totally dedicated to being a memory cache server. And if that's not even enough you can set up multiple servers as well. The sky is the limit. Note: if you try to start the memcached as root it will require you to specify a user under which it should run with an additional -u nobody.

Installation of the PHP MemCache extension: 

cd /files/download/

wget http://pecl.php.net/get/memcache-2.1.2.tgz

tar -xvf memcache-2.1.2.tgz

cd memcache-2.1.2

phpize && ./configure --enable-memcache && make

Copy the file memcache.so to the default module directory.

vi /etc/php.ini

Add

extension=memcache.so

/etc/init.d/httpd restart

If you check your phpinfo() you should see a MemCache section appear.

You can now fully use the MemCache functionality in your PHP.

 

References

http://www.danga.com/memcached/
http://dk.php.net/manual/en/ref.memcache.php


Please do not use the comment function to ask for help! If you need help, please use our forum.
Comments will be published after administrator approval.
Submitted by Santi Saez (not registered) on Tue, 2012-02-07 14:33.

Hey guys,

Actually "rpmforge" installs and outdated version of memcached (1.4.7, released ~2 years ago), I suggest using at least memcached 1.4.10, starting this release there is a big performance and scalability improvements (see developers release notes).

Using PowerStack repository you can easily run latest memcached stable version in your CentOS boxes (4, 5 and 6 releases supported, i686 + x86_64), last LAMP stack stable versions and other key packages like: nginx, HAproxy, node.js, redis, Varnish, etc.

All code + .spec files are available on GitHub, check out the wiki page for installation instructions:

http://powerstack.org

Regards,

Submitted by Vitek (not registered) on Tue, 2010-06-29 11:52.

There are 2 clients in php memcached and memcache, on Centos both can be definately installed by pecl:

pecl install memcached

pecl install memcache

Don't forget on dependencies:

yum install libmemcached-devel

yum install libmemcache-devel

Packages are's in remi or rpmforge repository


Vitek

Submitted by Anonymous (not registered) on Sun, 2009-05-17 23:10.

Great ! Thanks a lot ! Works fine for CentOS 4.7

yum install php-pecl-memcache   -- doesn´t work for CentOS 4.7


 

 

Submitted by Anonymous (not registered) on Sat, 2008-11-08 19:30.

All you need to do is

yum install php-pecl-memcache

Submitted by raven (not registered) on Mon, 2008-11-24 12:33.
that yum package won't work with php 5 right?