#Tutorial for setting up memcache on OSX and MAMP 2.0
##Prerequisites
- Load [this tutorial] (http://www.larsdesigns.net/content/how-setup-and-configure-memcache-mamp-version-2-osx-lion) for reference
- Install Xcode developer tools
- Install PECL
- Assumptions #1 - You are using PHP 5.3.6 but this tutorial should work with other versions and you understand you are recompiling php to get memcache working.
##Step 1 - Configure PECL Move the pear.conf file from the php directory you are working with to the home directory as a backup
sudo mv /Applications/MAMP/bin/php/php5.3.6/conf/pear.conf ~/
Load the autoconf dependency, decompress, configure, make and install it.
cd ~ curl -O http://ftp.gnu.org/gnu/autoconf/autoconf-2.69.tar.gz
tar -xf autoconf-2.69.tar.gz
cd autoconf-2.69
sudo ./configure
sudo ./make
sudo ./make install
Load the m4 dependency, decompress, configure, make and install it. (Not necessary for memcache, but handy for php, pecl, and pear
cd ~ curl -O http://ftp.gnu.org/gnu/m4/m4-1.4.16.tar.gz
tar -xf m4-1.4.16.tar.gz
cd m4-1.4.16
sudo ./configure
sudo ./make
sudo ./make install
Now that we have the autoconf and m4 installed, we need to download the source files for PHP 5.3.6 (or the version of php you are using within mamp) and include it as an extension for MAMP's PHP. It is important that the version of the PHP source files match the MAMP installed PHP version.
sudo mkdir /Applications/MAMP/bin/php/php5.3.6/include
cd /Applications/MAMP/bin/php/php5.3.6/include
sudo curl -O http://museum.php.net/php5/php-5.3.6.tar.gz
sudo tar -xf php-5.3.6.tar.gz
sudo mv php-5.3.6 php
cd php sudo ./configure
The end result should be in this directory: /Applications/MAMP/bin/php/php5.3.6/include/php that contains the PHP 5.3.6 source code.
We need to run (configure) so that PHP recognizes our new included source files.
sudo /Applications/MAMP/bin/php/php5.3.6/include/php/configure
Let's verify that MAMP's PHP has found our included source files by running:
sudo /Applications/MAMP/bin/php/php5.3.6/bin/php-config
You will receive php-config information printed out in the terminal. If you see these two lines, MAMP's PHP has found our included directory of source code:
--include-dir [/Applications/MAMP/bin/php/php5.3.6/include/php] --php-binary [/Applications/MAMP/bin/php/php5.3.6/bin/php]
Alright, now we should be able to finally run pecl and install the memcache extension.
sudo /Applications/MAMP/bin/php/php5.3.6/bin/pecl install memcache
After PECL is done building memcache, add the extension extension=memcache.so to your php.ini file using your favorite text editor or using a fancy shell command.
sudo emacs /Applications/MAMP/bin/php/php5.3.6/conf/php.ini
You can paste it at the top of the file just under [PHP] or the preferred place is just under the Dynamic Extensions section header:
;;;;;;;;;;;;;;;;;;;;;; ; Dynamic Extensions ; ;;;;;;;;;;;;;;;;;;;;;;
Restart Apache using the MAMP status window by clicking on the Stop Servers button and then clicking on the Start Servers buttons.
Let's verify that our extension has been added by clicking the Open start page button within the MAMP Status window and clicking on the PHP Info link in the top header of the MAMP start page. Memcache should now be listed on this info page.
We need to start memcached which is the daemon that the PHP memcache extension uses. This can be accomplished just by running the following command as your regular user and not sudo.
memcached &
Then run this command to verify that memcached is running:
memcached- h
Information about Memcached should be printed in the terminal window. Memcached was installed on my OSX Lion by default but in-case it is not, we can surely download the source and compile it to get the latest and greatest.
cd ~ curl -O http://memcached.googlecode.com/files/memcached-1.4.13.tar.gz
tar -xf memcached-1.4.13.tar.gz
cd memcached-1.4.13
sudo ./configure
sudo make
sudo make install
This version should compile just fine. Restart your terminal program and run:
memcached &
Then check to make sure the daemon is running by using:
memcached -h