ItecSoftware Logo

Hot To Install Memcache PHP On Mac OS X

Written by Peter Gilg on - like this:
install memcache php on mac osx

I recently installed the memcached daemon on my MacBook Pro, including the necessary PHP client for development purposes. I just prefer to work locally instead of using a VM running Linux. And the process is actually quite simple and straight forward. Please note, I have included both clients, the old standard one and the newer PECL extension, because I deal with different applications and also lots of people seems to get confused when they install one version and their memcache classes cannot get instantiated and throw errors. So, if in doubt, just install both.

Install memcache php on Mac OS X

These are the five (four if you know which extension you want) components needed:

– libevent (requred library for memcached)

– memcached daemon

– libmemcached (required library for the php client)

– php extension (standard)

– php extension (PECL)

Now open your terminal and off we go:

Note: if you don’t want to install wget, you can alternatively use “curl -O”)

Installing libevent

 $ cd /tmp
 $ wget http://www.monkey.org/~provos/libevent-1.4.13-stable.tar.gz (if you're brave, you can try the 2.0 beta)
 $ tar zxvf libevent-1.4.13-stable.tar.gz
 $ ./configure
 $ make
 $ sudo make install

Installing memcached

 $ wget http://memcached.googlecode.com/files/memcached-1.4.1.tar.gz
 $ tar xzvf memcached-1.4.1.tar.gz
 $ cd memcached-1.4.1
 $ ./configure
 $ make
 $ make test
 $ sudo make install
 $ memcached -d -P pidfile -l 127.0.0.1 (this will start the memcached daemon)
 $ ps aux | grep 'memcached' (this should confirm that memcached is running and how much memory is assigned to it)

Installing libmemcached

 $ wget http://launchpad.net/libmemcached/1.0/0.34/+download/libmemcached-0.34.tar.gz
 $ tar -zxvf libmemcached-0.34.tar.gz
 $ cd libmemcached-0.34
 $ ./configure
 $ make
 $ sudo make install

Installing PECL memcache extension

 $ cd /tmp
 $ pecl download memcached
 $ tar xzvf memcached-1.0.0.tgz
 $ cd memcached-1.0.0
 $ phpize
 $ ./configure
 $ make
 $ sudo make install

Installing PHP memcache extension

 $ cd /tmp
 $ wget http://pecl.php.net/get/memcache-2.2.4.tgz
 $ tar -zxvf memcache-2.2.4.tgz
 $ cd memcache-2.2.4
 $ phpize &&
 $ ./configure
 $ make
 $ sudo make install

Once all the steps are completed successfully, ensure that the extension directory is specified as the same as the output of the terminal after the extensions installed. Otherwise correct in php.ini.

Also add the line(s) to load the extension(s) in the php.ini file, in the extension section:

extension=memcached.so
extension=memcache.so

And finally restart apache:
$ sudo apachectl restart

And verify in phpinfo that memcache(d) is loaded and working.

Listed in Mac, Web Development

Tags: apache, memcache, memcached, PECL, php, php5-memache

3 responses to “Hot To Install Memcache PHP On Mac OS X”

  1. Rob says:

    Finally after searching A LOT for a solution, your guide worked, Except that you really need to notice the output of the files. For example i needed to link in the .so file in php.ini to:

    /opt/local/lib/php/extensions/no-debug-non-zts-20090626/

    Thanks.

  2. Handy resource indeed, however, this post doesn’t have a publish date. So, for what it’s worth, it’s always good to check the original download sites for the latest version of any libraries. For example, as of this comment date, the latest version of memcached (stable) is 1.0.2; the latest version of memcache (stable) is 2.2.6. I didn’t have wget for whatever reason, but this worked

    sudo /usr/bin/curl -O http://pecl.php.net/get/memcache-2.2.6.tgz

  3. This is a great article. I have read a few others which were incomplete and did not include the steps to start the memcached deamon. Thank you.

Leave a Reply

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