Patrick Ward words, code, and music

Adding the X-SendFile Module to MAMP Pro

I found myself getting tired of managing the local Apache, MySQL, and PHP installs on my Mac, especially when switching between different versions of PHP. So, I decided to give MAMP Pro another try. I purchased a version of 2.0.1 previously, so I all I had to do was upgrade to the latest version: 2.1.1.

However, the X-Sendfile extension isn’t packaged with MAMP Pro, so I had to install it myself.

The process was relatively simple, but it does require a few prerequisites:

For comparison sake, I’m running the following:

Installation steps:

  1. Download and untar the mod_xsendfile source code (I placed it in my ~/src directory and changed into that directory)
  2. Compile and install it into the Mac’s pre-installed Apache instance
sudo apxs -cia mod_xsendfile.c

If you run into an error similar to the following:

/usr/share/apr-1/build-1/libtool --silent --mode=compile /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.8.xctoolchain/usr/bin/cc    -DDARWIN -DSIGPROCMASK_SETS_THREAD_MASK -I/usr/local/include -I/usr/include/apache2  -I/usr/include/apr-1   -I/usr/include/apr-1   -c -o mod_xsendfile.lo mod_xsendfile.c && touch mod_xsendfile.slo
env: /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.8.xctoolchain/usr/bin/cc: No such file or directory
apxs:Error: Command failed with rc=65536

Then, you may have a more recent version of Xcode, which changed some paths. I found I had to create a symlink to fix the issue:

sudo ln -s /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.8.xctoolchain
  1. Copy the installed module file to the MAMP directory:
sudo cp /usr/libexec/apache2/mod_xsendfile.so /Applications/MAMP/Library/modules/
  1. This is the point that tripped me up. I didn’t know that MAMP PRO uses template files to recreate the Apache httpd.conf file, so even though I added the LoadModule xsendfile_module directive to the conf file, it was never recognized. In MAMP PRO, you need to edit the template file, which can be found via the top menu at File --> Edit Template --> Apache --> httpd.conf. Edit that file in the provided editor and place the following at the bottom of the other LoadModule directives. This lets you turn the feature off an on via the GUI in the same manner as modules that come preinstalled.
MAMP_xsendfile_module_MAMPLoadModule xsendfile_module modules/mod_xsendfile.so
  1. At this point, you should have X-Sendfile capability. Please refer to that project for details on how to use it.