Install memcached daemon / Install memcached extension using pecl
A little about Memcached
Memcached is a service that allows you to store in memory key-value data like strings or objects, from results like databases queries, API calls and drastically accelerating queries and reducing the load on your server. Memcached is being used by major websites like Youtube, Twitter, Digg, WordPress.com and many many more. In this artile we’re going to see how we can install Memcached on a server running CentOS.
To install Memcached, there are a few steps that you need to do, see bellow:
Installing Memcached (Daemon)
First we need some packages installed for Memcached to work on our server.
1 |
yum install libevent libevent-devel |
We download the latest (currently 1.4.10) version of memcached and untar it to our server:
1 2 3 4 |
cd /usr/local/src wget http://memcached.googlecode.com/files/memcached-1.4.10.tar.gz tar -xzf memcached-1.4.6.tar.gz cd memcached-1.4.6 |
Then we start configuring memcached, compile it and install it.
1 2 3 |
./configure make make install |
Preparing system to run with Memcached on startup.
1 2 3 4 5 |
touch /etc/init.d/memcached echo '#!/bin/sh -e' >> /etc/init.d/memcached echo '/usr/local/bin/memcached -d -m 128 -p 11211 -u nobody -l localhost' >> /etc/init.d/memcached chmod u+x /etc/init.d/memcached echo '/etc/init.d/memcached' >> /etc/rc.local |
And finanly we will start memcached daemon
1 |
/etc/init.d/memcached start |
PECL Memcache Module Installation:
Next step is to install the php module for using memcached directly from php. We can do this easily using PECL.
1 |
pecl install memcache |
Next in the folder /etc/php.d/ we create a file memcache.ini in which file we add the bellow content:
1 2 3 4 5 6 7 8 9 10 |
; /etc/php.d/memcache.ini extension = memcache.so memcache.allow_failover = 1 memcache.max_failover_attempts = 20 memcache.chunk_size = 32768 memcache.default_port = 11211 memcache.hash_strategy = standard memcache.hash_function = crc32 |
And next we restart the web server.
1 |
/etc/init.d/httpd restart |
That is all, it should look similar like in the image bellow: