02 7 / 2010

OSX, XAMPP and the memcache php modules

As a side note, php has two “memcache” modules, and this question via serverfault answers what the differences are between the two.

On my development machines, I use XAMPP and I recently needed to use the memcache and memcached modules. Unfortunately, XAMPP doesn’t come precompiled with them, I guess they aren’t popular modules. So after a couple of google searches and reading through ApacheFriend’s forums, I decided I had to build and install them from scratch.

First, I had to make sure I had xcode and the developer tools from Apple installed. If it’s not on the machine, download it from Apple’s developer site — http://developer.apple.com.

Along with the installation of XAMPP, I also installed the XAMPP developer package to get access to the configurations and other tools such as phpize.

Next, need to make sure the “PHP” binaries in /usr/bin points to XAMPP binaries rather then the one Apple installs on the computer. I made them all symbolic links so when I update XAMPP, I don’t have to do anything other then make sure the files exist.

Next, set up your compiling environment. For XAMPP 1.7.3, everything is precompiled using the i386 but on my machine any code compiled will use the default x86_64 architecture. To modify the environment settings, I ran the following:

$ CFLAGS="-arch i386 -g -Os -pipe -no-cpp-precomp"
$ CCFLAGS="-arch i386 -g -Os -pipe"
$ CXXFLAGS="-arch i386 -g -Os -pipe"
$ LDFLAGS="-arch i386 -bind_at_load"

Now, I could finally install the modules.

PHP module: memcache

Download the memcache source module using PECL:

$ pecl download memcache
$ tar xzf memcache-2.2.5.tgz
$ cd memcache-2.2.5
$ ./configure --with-php-config=/Applications/XAMPP/xamppfiles/bin/php-config
$ make
$ sudo make install

Modify the php.ini file (/Applications/XAMPP/xamppfiles/etc/php.ini) and add:


Restart apache. Voila. If you do a phpinfo, you’ll see the module settings under the memcache header.

PHP module: memcached

This module’s compilation process is a bit trickier because it requires the libmemcached library installed. You’ll need to download the source from http://libmemcached.org — as of this writing 0.41 is the latest version used.

$ tar xzf libmemcached-0.41.tar.gz
$ cd libmemcached-0.41
$ ./configure --prefix=/usr/local
$ make
$ sudo make install

Next, use pecl to download the memcached source module and compile it.

$ pecl download memcached
$ tar xzf memcached-1.0.2
$ cd memcached-1.0.2
$ ./configure --with-php-config=/Applications/XAMPP/xamppfiles/bin/php-config --with-libmemcached-dir=/usr/local
$ make
$ sudo make install

Again, just like the memcache module, need to add to the php.ini file:


Then, again restarting apache and verifying with phpinfo that the module successfully was created.


Permalink 19 notes