Tested on OSX 10.7.5 and 10.9 using PHP 5.3.6 and 5.3.20
Much of this info taken from http://www.lullabot.com/articles/setup-memcached-mamp-sandbox-environment
First, install the Memcached service
Install XCode tools
Save this script as install-memcached.sh
#!/bin/sh ## # Install memcached and dependencies smoothly on Mac OS X. # # Newer versions of these libraries are available and may work better on Mac OS X. # # See also http://topfunky.net/svn/shovel/memcached/install-memcached-linux.sh # # USE AT YOUR OWN RISK. # # AUTHOR: Geoffrey Grosenbach http://nubyonrails.com # # Some fixes are from http://blog.segment7.net/articles/2006/03/02/fast-memcached-on-os-x # # AFTER RUNNING THIS SCRIPT: # # Set the environment variable EVENT_NOKQUEUE to 1 # * csh and derivatives: setenv EVENT_NOKQUEUE 1 # * sh and derivatives (like bash): export EVENT_NOKQUEUE=1 # # You may also need to add /usr/local to your PATH. # PREFIX=/usr/local mkdir src cd src # Install libevent dependency curl -O http://www.monkey.org/~provos/libevent-1.1b.tar.gz tar xfz libevent-1.1b.tar.gz cd libevent-1.1b ./configure --prefix=${PREFIX} && make sudo make install cd .. # Install memcached and fixes curl -O http://www.danga.com/memcached/dist/memcached-1.1.12.tar.gz tar xfz memcached-1.1.12.tar.gz cd memcached-1.1.12 ./configure --prefix=${PREFIX} # in Makefile # LDFLAGS = -L/lib # LDFLAGS = -L${libdir} sed -e 's/-L\/lib/-L${libdir}/' Makefile > Makefile.new mv Makefile.new Makefile # also in Makefile # CFLAGS = -g -O2 -I/include # CFLAGS = -g -O2 -I${includedir} sed -e 's/-I\/include/-I${includedir}/' Makefile > Makefile.new mv Makefile.new Makefile # insert in memcached.c... # #undef TCP_NOPUSH # #ifdef TCP_NOPUSH curl -O http://topfunky.net/svn/shovel/memcached/fixmemcached_c.rb ruby fixmemcached_c.rb > memcached.c.new mv memcached.c.new memcached.c make sudo make install cd ../.. echo "Installation complete. Please add EVENT_NOKQUEUE=1 to your shell environment."
Set the permissions for the script and run it as root:
chmod 744 install-memcached.sh sudo ./install-memcached.sh
Add EVENT_NOKQUEUE=1
to the bottom of .bashrc in your home directory:
Open a NEW terminal window so the changes to .bashrc are recognized. Check that memcached is installed by entering memcached -h
in a terminal. You should see something like this as a result:
memcached 1.1.12 -p <num> port number to listen on -l <ip_addr> interface to listen on, default is INDRR_ANY -d run as a daemon ...etc
Clean up the install directory by deleting the 'src' directory and the 'install_memcacehd.sh' script
Install the Memchache PHP extension
Download memcache.so and put it in the /Applications/MAMP/bin/php5/lib/php/extensions/no-debug-non-zts-[date] directory.
Add extension=memcache.so
to php.ini (/Applications/MAMP/bin/php/php5.3.6/conf/php.ini)
Save the following scripts in /Applications/MAMP/bin:
startApache.sh
# /bin/sh /Applications/MAMP/Library/bin/apachectl start /Applications/MAMP/bin/startMemcached.sh
stopApache.sh
# /bin/sh /Applications/MAMP/Library/bin/apachectl stop /Applications/MAMP/bin/stopMemcached.sh
startMemcached.sh
# /bin/sh instances=11 for ((n=1; n<=$instances; n++)) do ((port=(11210+$n))) memcached -m 24 -p $port -d done
stopMemcached.sh
killall memcached
Set the permissions for the scripts:
cd /Applications/MAMP/bin sudo chmod 775 *.sh
Start and stop MAMP. You should see that you have 11 instances of memcached running on your system (ie. use Activity Monitor to see running processes)
Add this to the bottom of settings.php:
<?php $conf['cache_backends'][] = 'sites/all/modules/memcache/memcache.inc'; $conf['cache_default_class'] = 'MemCacheDrupal'; $conf['memcache_key_prefix'] = 'examplesite'; $conf['memcache_servers'] = array( 'localhost:11211' => 'default', 'localhost:11212' => 'content', 'localhost:11213' => 'filter', 'localhost:11214' => 'menu', 'localhost:11215' => 'page', 'localhost:11216' => 'views', ); $conf['memcache_bins'] = array( 'cache' => 'default', 'cache_content' => 'content', 'cache_filter' => 'filter', 'cache_menu' => 'menu', 'cache_page' => 'page', 'cache_views' => 'views', );
Download and install the memcache module
drush dl memcache drush en memcache memcache_admin
Configure Drupal memcache at http://example.com/admin/config/system/memcache