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

Method 1:  and run manually

yum install gcc libevent libevent-devel

cd /usr/local/src


tar -xf memcached-*.tar.gz

cd memcached-*

./configure make && make install

Memcached will be installed to /usr/local/bin. Let’s make sure everything went well by running memcached:

/usr/local/bin/memcached -u  -d

Then we’ll make sure it’s running

ps aux | grep memcached

netstat -anp | grep 11211

And finally kill it.

pkill memcached

Method 2: Install and run the service

Going all out – building a memcached

If you’re installing memcached on multiple machines then having an RPM handy is preferred. Make sure to run this as the ec2-user and not root.

yum install gcc libevent libevent-devel rpm-build perl-Test-Base

echo “%_topdir /home/ec2-user/rpmbuild” >> ~/.rpmmacros

mkdir -p /home/ec2-user/rpmbuild/{SPECS,BUILD,SRPMS,RPMS,SOURCES}

wget rpmbuild -ta memcached-*.tar.gz

The RPM will be created in ~/rpmbuild/RPMS/x86_64/ or ~/rpmbuild/RPMS/i386/ depending on whether you chose a 32 or 64 bit AMI. Copy the rpm to your home directory and run the below to install memcached to /usr/bin/memcache

yum localinstall memcached-*.rpm --nogpgcheck

The beauty of this approach is that you can now do the following to start or stop memcached

service memcached status service memcached start service memcached stop

And finally you can enable memcached at startup with this simple command:

chkconfig memcached on

Install  php-pecl-memcache

#if apt-get, rpm, or yum doesn’t work

cd /usr/src/
tar -zxvf memcached-2.2.4.tgz
cd memcached-2.2.4
phpize && ./configure –enable-memcache && make
cp modules/ /usr/lib/php/modules/

# Note: packaged extension modules are now loaded via the .ini files
# found in the directory php.ini

php -i | grep php.ini

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

add php.ini


restart service https

/etc/init.d/httpd restart

Note: if fails, install the following packages

yum install php-devel
yum install zlib-devel
yum install zlib zlib-devel

Check memcache

php -i | grep memcache

# more testmemcach.php

$memcache = new Memcache;
$memcache->connect(‘’, 11211);

# php testmemcach.php

Memcache Object
[connection] => Resource id #5


Print Friendly, PDF & Email



Bài viết liên quan

Be the first to comment

Để lại lời nhắn