Memcached with MAMP 2.0.5 and Brew

Requires that you have brew installed which is pretty easy, info here, but run:

/usr/bin/ruby -e "$(/usr/bin/curl -fsSL \
https://raw.github.com/mxcl/homebrew/master/Library/Contributions/install_homebrew.rb)"

We ultimately want to install memcached-php, and since libmemcached and memcached are both dependencies for it we can get them all at once. First we need to access the proper repository with “brew tap josegonzalez/php”

Io:/ $ brew tap josegonzalez/php
Cloning into /usr/local/Library/Taps/josegonzalez-php...
remote: Counting objects: 757, done.
remote: Compressing objects: 100% (386/386), done.
remote: Total 757 (delta 308), reused 703 (delta 267)
Receiving objects: 100% (757/757), 105.33 KiB, done.
Resolving deltas: 100% (308/308), done.
Tapped 26 formula

Now we can access the memcached-php with “brew install memcached-php”

Io:/ $ brew install memcached-php
==> Installing memcached-php dependency: memcached
==> Downloading http://memcached.googlecode.com/files/memcached-1.4.13.tar.gz
==> ./configure --prefix=/usr/local/Cellar/memcached/1.4.13
==> make install
==> Caveats
You can enable memcached to automatically load on login with:
mkdir -p ~/Library/LaunchAgents
cp /usr/local/Cellar/memcached/1.4.13/homebrew.mxcl.memcached.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.memcached.plist
If this is an upgrade and you already have the homebrew.mxcl.memcached.plist loaded:
launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.memcached.plist
cp /usr/local/Cellar/memcached/1.4.13/homebrew.mxcl.memcached.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.memcached.plist
Or start it manually:
/usr/local/bin/memcached
Add "-d" to start it as a daemon.
==> Summary
/usr/local/Cellar/memcached/1.4.13: 9 files, 168K, built in 5 seconds
==> Installing memcached-php dependency: libmemcached
==> Downloading http://launchpad.net/libmemcached/1.0/1.0.4/+download/libmemcached-1.0.4.tar.gz
==> ./configure --prefix=/usr/local/Cellar/libmemcached/1.0.4
==> make install
/usr/local/Cellar/libmemcached/1.0.4: 224 files, 3.1M, built in 33 seconds
==> Installing memcached-php
==> Downloading http://pecl.php.net/get/memcached-2.0.1.tgz
######################################################################## 100.0%
==> phpize
==> ./configure --prefix=/usr/local/Cellar/memcached-php/2.0.1 --with-libmemcached-dir=/usr/local/Cellar/libmemcached/1.0.4
==> make
==> Caveats
To finish installing memcached-php:
* Add the following line to /usr/local/etc/php.ini:
extension="/usr/local/Cellar/memcached-php/2.0.1/memcached.so"
* Restart your webserver.
* Write a PHP page that calls "phpinfo();"
* Load it in a browser and look for the info on the memcached module.
* If you see it, you have been successful!
==> Summary
/usr/local/Cellar/memcached-php/2.0.1: 4 files, 100K, built in 6 seconds

The rest of the process is actually spelled out in the brew output. You can memcached manually as a daemon by running the following.

memcached -d

Alternatively you can start memcached up every time you log in by running these commands.

mkdir -p ~/Library/LaunchAgents
cp /usr/local/Cellar/memcached/1.4.13/homebrew.mxcl.memcached.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.memcached.plist

Next we need to install the extension in MAMP, so copy the following into the section labeled “; Extensions” in your php.ini file. Mine is located at /Applications/MAMP/bin/php/php5.3.6/conf/php.ini.

extension="/usr/local/Cellar/memcached-php/2.0.1/memcached.so

Restart the Apache service via the MAMP console and you should be good to go. You can check by making a file called phpinfo.php in your root that contains ““. Loading http://localhost:PORT/phpinfo.php will have a section titled “memcached” if the module loaded successfully.

PS – don’t forget to actually start the memcached server via “memcached -d” or you won’t actually be using it even if the module is enabled :/

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *