Hot To Install Memcache And PHP Client On Mac Snow Leopard
I recently installed the memcached daemon on my MacBook Pro, incuding 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.
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.