memcached是一套分布式的高速缓存系統,通常只是當作快取系統使用,所以使用memcached的應用程式在寫回較慢的系統時(像是後端的資料庫)需要額外的程式碼更新memcached內的資料。(reference from wiki)

預計完成的安裝環境

  • libevent (memcached requirement)
  • Memcached 1.4.15 Server, download it
  • PHP Memcached extension 2.10, download it

Memcached Server

In MAMP:

brew install libevent

tar -zxvf memcached-1.4.15.tar.gz

cd memcached-1.4.15/

./configure --prefix=/Applications/MAMP/bin/php/php5.4.4/bin/php   # depend on your PHP version

make

make install

Memcached Server Commands

  • memcached -d -m 50 -p 11211 -u root   # start memcached daemon, m: how many mega bytes you want, p: port
  • killall memcached   # stop memcached daemon

PHP Memcached extension

In MAMP

brew install libmemcached

tar -zxvf memcached-2.1.0.tgz

cd memcached-2.1.0/
/Applications/MAMP/bin/php/php5.4.4/bin/phpsize   # to build PHP extension

./configure -enable-memcache -with-php-config=/Applications/MAMP/bin/php/php5.4.4/bin/php-config   # depend on your PHP version

make

make install

You will see this message "/Applications/MAMP/bin/php/php5.4.4/lib/php/extensions/no-debug-non-zts-20100525/" if success

add "extension=memcached.so" to your php.ini and restart your web server

In Ubuntu


$ sudo apt-get install memcached

$ sudo apt-get install php5-memcached

$ sudo /etc/init.d/apache2 restart

Memcached Test Script

```
<h2><span style="color: #3366ff;">Error "configure: error: Cannot find php_session.h" on MAMP</span></h2>

<ul>
	<li><span style="line-height: 22px;"><a href="http://www.php.net/downloads.php" target="_blank">Download PHP source code depending on your PHP version</a></span></li>
	<li>Unzip/tar the php source archive and move it to "/Applications/MAMP/bin/php/php5.4.4/include"</li>
	<li>Rename the php source directory to just php (so then it will look like "/Applications/MAMP/bin/php/php5.4.4/include/php")</li>
	<li>Run "./configure" under "/Applications/MAMP/bin/php/php5.4.4/include/php" to create header files</li>
</ul>
<h2><span style="color: #3366ff;">Reference</span></h2>
<ul>
	<li><span style="line-height: 22px;"><a href="http://blog.saycoo.com/archives/18" target="_blank">Memcached Server + Client 完全安裝</a></span></li>
	<li><a href="http://www.lecloud.net/post/3102678831/install-memcached-php-memcached-extension-under-mac" target="_blank">Install Memcached + PHP Memcached Extension under Mac OS X Snow Leopard</a></li>
	<li><a href="http://www.lullabot.com/articles/setup-memcached-mamp-sandbox-environment" target="_blank">Setup a Memcached-Enabled MAMP Sandbox Environment</a></li>
	<li><a href="http://de2.php.net/manual/en/memcached.installation.php" target="_blank">PHP: Installation</a></li>
</ul>