I. Installing the Memcahce
1. Install the dependency pack libevent
Memcache needs to be installed libevent, so you may need to do it before installing
Shell Code
- Yum Install Libevent-devel
2. Installing Memcache
Download the latest version of 1.4.13 from http://memcached.org/
Shell Code
- TAR-XZVF memcached-1.4. 13.tar.gz
- CD memcached-1.4. -
- ./configure--prefix=/usr/local/memcache
- Make && make install
3. Configure memcached self-boot
Copy the source directory under Scripts/memcached.sysv to/etc/init.d/memcached, you need to modify the/etc/init.d/memcached line as follows:
Shell Code
- Chown $USER/usr/local/memcache/bin/memcached
- Daemon/usr/local/memcache/bin/memcached-d-P $PORT-u $USER-M $CACHESIZE-C $MAXCONN-P/VAR/RUN/MEMCACHED/MEMCACHED.P ID $OPTIONS
(Just modify the path of memcached)
Then execute the following command:
Shell Code
- chmod 755 memcached
- Chkconfig--add memcached
Start try
Shell Code
- Service memcached Start
II. Installing the PHP memcahce extension
The reference pecl.php.net has two memcache extensions:
Memcache memcached Extension
memcached PHP extension for interfacing with memcached via Libmemcached Library
The memcached version is newer and uses the Libmemcached library. Libmemcached is thought to have done a better job of optimizing, and should have a higher performance than PHP only version of Memcache. So the installation here is memcached (assuming php5.4 is already installed in/usr/local/php).
1. Installing Dependent libraries
Https://launchpad.net/libmemcached/1.0/1.0.4/+download/libmemcached-1.0.4.tar.gz
Shell Code
- TAR-XZVF libmemcached-1.0. 4.tar.gz
- CD libmemcached-1.0. 4
- ./configure
- Make
- Make install
2. Installing memcached
http://pecl.php.net/get/memcached-2.0.1.tgz Download, installation instructions:
Shell Code
- Tar vxzf memcached-2.0. 1.tgz
- CD memcache-2.0. 1
- Phpize
- ./configure--enable-memcache--with-php-config=/usr/local/php/bin/php-config
- Make
- Make install
After loading, the final display installing shared extensions:/usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/, Generate the memcached.so in this directory, and copy it to the directory that php.ini Extension_dir points to. Modify php.ini Add Line Extension = memcached.so restart Apache, and then go to the page to open the Phpinfo information page to see if the memcached extension was installed successfully.
Write a test to see
PHP code
- <?php
- $m = new Memcached ();
- $m->addserver (' localhost ', 11211);
- $m->set (' username ', ' Allen ');
- Var_dump ($m->get (' username '));
- ?>
There is also a PHP written memcache monitoring tool that can be downloaded
http://livebookmark.net/journal/2008/08/28/memcachephp-flushes-servers/
This article is how to set PHP session to Memcache
http://koda.iteye.com/blog/466667
Go from blog->http://koda.iteye.com/blog/665761
Install Memcache and PHP memcache extensions under Cenos.