Hello, I’m a web craftsman with a passion for the modern web. I build web applications and play with social services and communities.

November 6, 2011 at 4:29 pm

There is still plenty of interest in my old article “Develop memcached web apps with XAMPP under Mac OS X” so I decided to write a little follow up.

XAMPP for OS X hasn’t seen any updates in quite a while so I decided to go with MAMP after upgrading to Mac OS X Lion (10.7.2 as of now). Quite ironic since I originally changed from MAMP to XAMPP because of the lack of updates from MAMP. However, both are quite similar when it comes to installing extensions from pecl or pear so you may have some luck applying the following steps to either dev environment.

Also while I am installing the mongo driver for php here, the very same steps should work for other pecl packages such as memcache, uploadprogress or xdebug. So let’s get started!

Prerequisites:

  • Install XCode (I’m on 4.2 at the moment)
  • Install MAMP (2.0.5)
Install MongoDB if you haven’t done so yet: (I’m using homebrew for that, it’s the fastest way to get MongoDB running)
  1. $ brew install mongodb
  2. Start the MongoDB server
    $ mongod

Now it’s time to install the mongo php extension:

  1. Download the matching version of the php source code from php.net (MAMP 2.0.5 comes with PHP 5.3.6)
  2. Create an include-folder in your MAMP php installation
    $ mkdir /Applications/MAMP/bin/php/php5.3.6/include
  3. Extract the php source code into that new folder. The extracted folder is called php-5.3.6.
  4. Rename that folder to just php, then the php source code should be located here:
    /Applications/MAMP/bin/php/php5.3.6/include/php
  5. Change into that directory and configure php:
    $ cd /Applications/MAMP/bin/php/php5.3.6/include/php
    $ ./configure
  6. MAMP comes with a weird pear config file that causes issues, let’s remove it:
    $ rm /Applications/MAMP/bin/php/php5.3.6/conf/pear.conf
  7. Now install the mongo driver with pecl:
    $ cd /Applications/MAMP/bin/php/php5.3.6/bin
    $ ./pecl install mongo
  8. Activate the extension in your php.ini:
    extension=mongo.so

And that’s all. From now on you only need the last two steps to install other extensions.


March 30, 2010 at 9:07 pm

While developing scalable web applications you will come across memcached at some point. Memcached is a free & open source, high-performance, distributed memory object caching system.

XAMPP is great for development in a local environment but does not come with a php memcached extension preinstalled. Since there are 2 good memcached php extensions in the PECL repository (memcached and memcache) it could be as easy as installing them through XAMPPs PECL installer. Unfortunately XAMPP for Mac (1.7.3) is still compiled for 32bit and the PECL installer would create a 64bit snow leopard extension. So let’s do it manually by setting some 32bit flags…

Install memcache PHP extension (2.2.5) for XAMPP (1.7.3) under Mac OS X 10.6 Snow Leopard (10.6.2)

  1. make sure Apple Developer Tools (Xcode) are installed
  2. make sure XAMPP Developer Package is installed
  3. $ cd /tmp
  4. $ pecl download memcache
  5. $ tar xzf memcache-2.2.5.tgz
  6. $ cd memcache-2.2.5
  7. $ /Applications/XAMPP/xamppfiles/bin/phpize-5.3.1
  8. This line looks just a bit complicated because it tries to deal with architecture problems between XAMPP (compiled for 32bit) and Snow Leopard (compiles everything by default to 64bit)
    $ MACOSX_DEPLOYMENT_TARGET=10.6 CFLAGS='-O3 -fno-common -arch i386 -arch x86_64' LDFLAGS='-O3 -arch i386 -arch x86_64' CXXFLAGS='-O3 -fno-common -arch i386 -arch x86_64' ./configure --with-php-config=/Applications/XAMPP/xamppfiles/bin/php-config-5.3.1
  9. $ make
  10. $ sudo make install
  11. change XAMPPs php.ini to load the extension: (in [Dynamic Extensions])
    extension=memcache.so

Those steps enable you to use memcached in your PHP Code. But to actually test the application and caching in your local development environment you have to start the memcached daemon. Fortunately memcached got already installed by the Mac OS X Developer Tools (Xcode).

Just go ahead and start the memcached daemon:

$ memcached -m 8 -l 127.0.0.1 -p 11211 -d

-m 8 limits memcached to use a maximum of 8MB RAM to operate

-l 127.0.0.1 -p 11211 is the ip and port to listen on

-d tells it to start as a daemon

(instead of -l and -p you can also use -s to use an unix domain socket)