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

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])

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 -p 11211 -d

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

-l -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)

33 Responses to “Develop memcached web apps with XAMPP under Mac OS X”

  1. Yaroslav says:

    step 7 after
    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

    i get – configure: error: invalid variable name: `–with-php-config’

  2. Matthias says:

    Careful when copying the commands from here. Looks like some ‘ (single quotes) didn’t get copied correctly. You have a question mark in your command after “x86_64″ that doesn’t belong there.

  3. Andreas says:

    Hey, I got it working, thanks!

    Matthias, besides the quotes there is one more thing to note here. It’s not -with-php-config but –with-php-config
    You have to use two minus chars (–), not just one.

  4. Andreas says:

    So I see… the comment system here makes two — minus chars to appear as one.

    You don’t happen to know how to install the php memcached api instead of memcache?
    I’ve heard it’s better.

  5. Matthias says:

    Yeh it seams to be WordPress who converts two dashed into one. Hmm..will see if I find a way around that.

    I went with memcached instead of memcache because memcache needs libmemcache to be installed while memcached has no dependencies. And since this is a development setup I wanted to go with the easier option. For production systems you shouldn’t really be using XAMPP anyway.

  6. Andreas says:

    I guess you meant the opposite, you went with memcache instead of memcached, since memcached requires libmemcached or..?

    Why shouldn’t I be using XAMPP in a production environment really?

  7. Matthias says:

    Yeah maybe. memcache has no dependencies. I don’t see the point of running XAMPP on a production system since every Linux distribution comes with easy ways to install a minimal LAMP system. XAMPP has a lot of features included that won’t be needed by most production servers. That’s good for development machines, because everyone wants to create different application out of the box, but on production servers this would generate a lot of unnecessary overhead.

  8. Rada Varshavskaya says:

    A couple notes.

    1. If you already installed the regular XAMPP package, you will need to download and install the XAMPP Developer package before you can re-compile as detailed in this post.

    2. Steps 6 and 7 look as though you execute two lines below:


    …and then

    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

    That’s not correct – what you actually need is:

    /Applications/XAMPP/xamppfiles/bin/phpize-5.3.1 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′

    … then

    ./configure –with-php-config=/Applications/XAMPP/xamppfiles/bin/php-config-5.3.1

    … and finally make, make install

    Otherwise thank you so much Matthias, truly helpful post!

  9. Rada Varshavskaya says:

    (Note for my post above, WordPress replaces double dashes with single dashes, check Matthias’s original post for correct dashes)

  10. Matthias says:

    Thanks for your input Rada,

    when I installed XAMPP the last time, I definitely executed all commands as explained. phpize first, then setting the environment vars AND ./configure in one line to make sure ./configure makes use of the environment variables. I’ll pay more attention to this next time I need to install memcached (also I hope that I won’t have to do this again until XAMPP moved to 64bit)

    The need for the installed XAMPP Developer package is a good point and I’ll add that to the post.

  11. Richard says:

    thank you so much for this!

  12. Rada Varshavskaya says:

    Hi Matthias, Rada again. I had errors when running #7 and #8 as posted and when I tried environment options with phpize it fixed the errors but then memcache wouldn’t load. So you were right that the options belong with the config. However the options should go after the config command… I think that was the source of errors.

    This is what’s finally worked for me (if you are trying this at home fix the single/double dash issue as noted in other comments)

    % /Applications/XAMPP/xamppfiles/bin/phpize-5.3.1

    % ./configure 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′ –with-php-config=/Applications/XAMPP/xamppfiles/bin/php-config-5.3.1

    % make

    % make install

  13. renars says:

    Hi everyone, can somebody tell me what is the issue about the XAMPP package and actual Web server built-in MacOs system. I spent so much time already and in the end it turns out that i have installed memcached already, but not in the right place, i mean installed in against built-in system, not the XAMPP one.

    Is it really worth to have a XAMPP on your computer, maybe can get along with built-in stuff?

    Also if yes, how can i make that they do not conflict, because my phpinfo from XAMPP now does not see memcached at all :)

    Does anybody know some solution to this?

    Thanks in advance!

    Best regards

  14. Shiki says:

    Thanks a lot! This worked for MAMP as well :)

  15. [...] followed the steps in Matthias Schmidt’s blog. The tutorial is for XAMPP but it should be the same (more or less) with MAMP. June 17, 2010 9:12 [...]

  16. Jeff Lyon says:

    Just wanted to say thanks–I was going crazy trying to get this working and your guide really helped me out. Finally I can rest easy :)

    The only part that didn’t work for me was Step 4 (the PECL download)… not sure why, but on my OS X 10.6.5 box, the pecl command was having a couple of issues (permissions, and finding the package). It’s super easy to find the most up-to-date source at on the PECL site (just go there and search for memcache)… not sure why I’m pointing this out since it’s nit-picking to the point of stupidity, guess it’s just my OCD.

    Anyway, seriously, thanks so much!

  17. [...] required steps for download, configure and compile as described by Matthias Schmidt in his Blog: http://blog.m-schmidt.eu/2010/03/30/develop-memcached-web-apps-with-xampp-under-mac-os-x/Make sure Apple Developer Tools (Xcode) are installed. Download an unpack the pecl package in /tmp. [...]

  18. Raf says:

    I’m trying to make memcache work with MAMP (not XAMPP), when I run phpize I got this error:

    /opt/local/bin/autoconf: /opt/local/bin/autom4te: /opt/local/bin/perl: bad interpreter: No such file or directory
    /opt/local/bin/autoconf: line 492: /opt/local/bin/autom4te: Unknown error: 0

    I’m on mac os x snow leopard 10.6.6

    any idea?

  19. Hi Matthias,

    I’m getting this error when i’m trying to run the last code.

    memcached -m 8 -l -p 11211 -d
    dyld: Library not loaded: /usr/lib/libevent-1.4.2.dylib
    Referenced from: /usr/bin/memcached
    Reason: image not found
    Trace/BPT trap

    Did i missed anything?

  20. coodix says:

    Thank you very much! It work’s for me!

  21. allie says:

    I’m getting a error while running ./configure

    checking for session includes… configure: error: Cannot find php_session.h

    any help would be appreciated.

  22. Matthias says:

    Hey allie,

    did you do step 2? Installing XAMPP dev package?

  23. [...] I’m attempting to install the php memcached extension on Mac OS X with XAMPP for my development environment. I’m following the directions for http://m-schmidt.eu/2010/03/30/develop-memcached-web-apps-with-xampp-under-mac-os-x/ [...]

  24. [...] 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 [...]

  25. Paul says:

    I realize this is an old post but I’m attempting to follow. I also receive the cannot find php_session.h error. Google doesn’t turn up anything about an extra xampp dev package… what are you referring to? Reinstalling xampp itself?

  26. Gregory says:

    I realize this is an old article but not one step of this seems to work anymore (with XAMPP dev tools and xcode installed)

    Pecl isn’t found. It’s in the bin folder of XAMPP but doesn’t want to execute, even when chmod’ed to.

    Ok, lame, so download memcache anyhow.

    Phpize isn’t in the XAMPP bin folder.

    Well crap. Nothing works at all.

  27. Gregory says:

    Ok… argh. XAMPP installers are stupid.

    To get this to work – first make sure that..

    1. the /Applications/XAMPP/xamppfiles/bin directory is in your /etc/paths file
    2. all the binaries in that folder are executable (chmod -x) as XAMPP doesn’t do this automatically.
    3. Then run chmod 777 on all the binaries in that directory, as otherwise they plain don’t run.

    Then… FINALLY pecl will work, as will php-ize


  28. tarique says:


    What to do if I want to install memcache in OSX lion? I tried this way, but not working.

    Can you please suggest ?

  29. http://dream-analysis.org says:

    Just wanna state that this is very helpful, Thanks for taking your time to write this.

  30. Addis says:

    hey everyone,
    i’ve tried every step carefully and it worked on my mac (os x 10.7), but when i tried to install on my friend’s mac (os x 10.6), it failed even if i follow the same step as written here. The problem coming from step 8, i get message “c compiler cannot create executables”. My friend’s mac has xcode installed.
    Can anyone suggest anything? or maybe just a link to the similar problem like that?

    when u get to step 8, change this line MACOSX_DEPLOYMENT_TARGET=10.7 because your mac os version is 10.7, not 10.6 and this way works perfectly fine for me. Hope this help!


  31. tim peterson says:

    @MatthiasSchmidt thanks for the tutorial.

    I successfully completed all steps but still I can’t instantiate a new Memcache object (following the simple demo code on php.net http://www.php.net/manual/en/memcached.set.php).

    This has got to be a path issue, right? Any thoughts?

    thanks, tim

  32. Alex says:


    Just wanted to say thanks. This was helpful.


  33. Niraj says:

    I am new to mac and using OS X 10.7 and I get error like. -bash: ./configure: No such file or directory.
    while running step 8

    any suggestion ???
    THank you.

Leave a Reply