-
23
Aug
In this how to i will describe how to install memcached on your server with PHP Extension. 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. My server is running CentOS 5.3 with CPanel.
1) Install memcached.
Enable rpmforge respository to install latest memcached rpm using yum.
For i386 / i686
rpm -Uhv http://apt.sw.be/redhat/el5/en/i386/rpmforge/RPMS/rpmforge-release-0.3.6-1.el5.rf.i386.rpm
For x86_64
rpm -Uhv http://apt.sw.be/redhat/el5/en/x86_64/rpmforge/RPMS//rpmforge-release-0.3.6-1.el5.rf.x86_64.rpm
Use yum to install memcached
yum -y install memcached
As soon as memcached installation completed, edit options for memcached in /etc/sysconfig/memcached to meet your need.
vi /etc/sysconfig/memcached
PORT=”11211″ #define on which port to urn
USER=”nobody” #same as apache user
MAXCONN=”1024″ #maximum number of connections allowed
CACHESIZE=”64″ #memory used for caching
OPTIONS=”" #use for any custom options
Save the file. All options can be seen by using following command
memcached -h
Start memcached
/etc/init.d/memcached start
Starting Distributed memory caching (memcached): [ OK ]
to check the running status of memcached
/etc/init.d/memcached status
memcached (pid 6475) is running…
and
netstat -anp | grep 11211
tcp 0 0 :::11211 :::* LISTEN 6475/memcached
udp 0 0 0.0.0.0:11211 0.0.0.0:* 6475/memcached
2) Install PHP Extension.
Download and install latest stable memcache version from PECL.
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
memcache.so will be install in php modules directory, now enable memcache.so extension in php.ini
To find out your php.ini location, execute following command
php -i | grep php.ini
Configuration File (php.ini) Path => /usr/local/lib
Loaded Configuration File => /usr/local/lib/php.ini
vi /usr/local/lib/php.ini
extension = “memcache.so”
save the file and restart httpd server.
/etc/init.d/httpd restart
To check is memcache extension loaded in php, execute following command.
php -i | grep memcache
memcache
memcache support => enabled
memcache.allow_failover => 1 => 1
memcache.chunk_size => 8192 => 8192
memcache.default_port => 11211 => 11211
memcache.default_timeout_ms => 1000 => 1000
memcache.hash_function => crc32 => crc32
memcache.hash_strategy => standard => standard
memcache.max_failover_attempts => 20 => 20
Registered save handlers => files user sqlite memcache
PWD => /usr/src/memcache-2.2.5
_SERVER["PWD"] => /usr/src/memcache-2.2.5
_ENV["PWD"] => /usr/src/memcache-2.2.5
This information can also be seen using phpinfo().
If you have question please comment.
- Published by Sohail Riaz in: Linux
- If you like this blog please take a second from your precious time and subscribe to my rss feed!











10 Responses to “How To Install memcached with memcache PHP Extension on CentOS 5.x”
Very nice tutorial. You can also check some more details in the link given below.
http://howtosetup.in/component/content/article/11-how-to-setup-memcached-for-php-in-the-server.html
I have done all but it doen’t work, I am running 5.3.2, I had to recompile php to support libcurl, now I broken memcached and I am stuck with it.
@Islam: Which Linux Version you are using. You said it doesn’t work and in mean time you said when you compile php with libcurl it broke memcached?
————
Regards,
@Souhail: it’s a centos, kernel 2.6.18 ..
there is no relationship between libcurl and memcached, the only thing is that after I recompiled PHP, libcurl worked, and memcached not, I tried many times with too versions of the package and nothing! PHP is version 5.3.2
@Islam: I knew there is no relationship between libcurl and memcached. All you have to do is recompile PHP and then reinstall memcached using the source because it uses phpize to determine the PHP version, so you need to reinstall memcached everytime you recompile PHP.
It will be good if you posted any error which you facing while installing memcached
——————–
Thank you Sohail, I got it working now.
I was phpizing against the wrong version of php, .. another thing is that extension = “memcache.so” doesn’t work with the ” ” , maybe you should fix that in the tutorial.
thank you very much for your help.
This was right on the money. Thanks for posting it.
Thanks. It worked for me
Leave a Reply