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

Develop memcached web apps with XAMPP under Mac OS X

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)

  • Share this:
  • Share
    • Email
    • Digg
    • Reddit
    • StumbleUpon
    Cognitions, Server, Web 2.0 | 27 comments | Tags: memcached, PECL, PHP

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

    1. spacer Yaroslav says:
      April 20, 2010 at 1:41 pm

      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. spacer Matthias says:
      April 20, 2010 at 1:44 pm

      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. spacer Andreas says:
      April 21, 2010 at 11:05 pm

      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. spacer Andreas says:
      April 21, 2010 at 11:34 pm

      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. spacer Matthias says:
      April 21, 2010 at 11:40 pm

      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. spacer Andreas says:
      April 22, 2010 at 7:03 am

      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. spacer Matthias says:
      May 3, 2010 at 8:16 pm

      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. spacer Rada Varshavskaya says:
      May 18, 2010 at 5:36 pm

      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:

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

      …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. spacer Rada Varshavskaya says:
      May 18, 2010 at 5:38 pm

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

    10. spacer Matthias says:
      May 18, 2010 at 7:07 pm

      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. spacer Richard says:
      May 19, 2010 at 2:28 pm

      thank you so much for this!

    12. spacer Rada Varshavskaya says:
      May 19, 2010 at 3:11 pm

      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. spacer renars says:
      May 24, 2010 at 7:36 pm

      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. spacer Shiki says:
      June 17, 2010 at 9:46 am

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

    15. Memcache on MAMP 1.9 says:
      November 27, 2010 at 3:24 pm

      [...] 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. spacer Jeff Lyon says:
      December 22, 2010 at 8:32 am

      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. HowTo install memcache extension: OS X, MAMP [PRO], php 5.2.3 « uscreen says:
      January 19, 2011 at 12:38 pm

      [...] required steps for download, configure and compile as described by Matthias Schmidt in his Blog: 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. spacer Raf says:
      March 1, 2011 at 9:45 pm

      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. spacer Wordpress Elite says:
      March 5, 2011 at 12:54 am

      Hi Matthias,

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

      memcached -m 8 -l 127.0.0.1 -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?
      Thanks!

    20. spacer coodix says:
      April 30, 2011 at 1:08 pm

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

    21. spacer allie says:
      June 8, 2011 at 9:00 pm

      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. spacer Matthias says:
      June 9, 2011 at 10:54 am

      Hey allie,

      did you do step 2? Installing XAMPP dev package?

    23. installing memcached php extension XAMPP – Mac OS X (not working) | Gravity Layouts says:
      November 3, 2011 at 7:29 am

      [...] 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 m-schmidt.eu/2010/03/30/develop-memcached-web-apps-with-xampp-under-mac-os-x/ [...]

    24. Develop MongoDB web apps with MAMP under Mac OS X | Matthias Schmidt – Bloggertastic says:
      November 6, 2011 at 4:29 pm

      [...] 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. spacer Paul says:
      January 25, 2012 at 7:49 pm

      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. spacer Gregory says:
      February 7, 2012 at 6:00 pm

      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. spacer Gregory says:
      February 7, 2012 at 6:30 pm

      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

      *argh*

    Leave a Reply

    Click here to cancel reply.


    Related searches:
    memcached memcache config installed configure
    gipoco.com is neither affiliated with the authors of this page nor responsible for its contents. This is a safe-cache copy of the original web site.