Install apache module X-Sendfile on MAMP

5k views Asked by At

How can I install X-Sendfile apache module so that MAMP can use it?

I have followed these instructions to install X-Sendfile, but it didn't work (it seems like it just installed it for the default apache installation). I also tried to manually copy /usr/libexec/apache2/mod_xsendfile.so to /Applications/MAMP/Library/modules/, but that produced the following error when restarting Apache:

Cannot load /Applications/MAMP/Library/modules/mod_xsendfile.so into server: cannot create object file image or add library

2

There are 2 answers

3
Tad Bumcrot On BEST ANSWER

naabster's answer is correct if your MAMP binary is built for the same architecture as your kernel. The problem you're having might be that MAMP is not built using the same architecture -- I have Lion running here (10.7.3) with XAMPP 1.7.3 and I just ran across the same issue you were having.

Here's how I figured out what was wrong on my system, and how I fixed it. If your issue is the same as mine, then you should be able to follow along and verify as you go.

First, here's the output of 'uname -a' to show you that what I'm running:

Darwin Tads-Mac-Pro.local 11.3.0 Darwin Kernel Version 11.3.0:
Thu Jan 12 18:47:41 PST 2012; root:xnu-1699.24.23~1/RELEASE_X86_64 x86_64

Here are the steps I took to track down the problem and fix it:

  1. Figure out what attributes the other (working) modules had that my freshly-built xsendfile module was missing. I picked mod_headers.so as an example. The command to find that info is 'file [filename]'. I'm running this from a terminal cd'd to the /Applications/XAMPP/xamppfiles/modules directory:

    file mod_headers.so 
    mod_headers.so: Mach-O universal binary with 2 architectures
    mod_headers.so (for architecture i386): Mach-O bundle i386
    mod_headers.so (for architecture ppc):  Mach-O bundle ppc
    

    As you can see, XAMPP kindly provides a universal binary that supports i386 and ppc architectures. However, because the Lion kernel is running x86_64, everything I build using apxs unless I tell it to otherwise will be x86_64.

  2. Check the mach-o bundle type and architecture(s) supported by the module that was built with the recommended apxs build command ('sudo apxs -cia mod_xsendfile.c'). Because we're passing '-i' the apxs will install the .so into the default apache modules dir ... /usr/libexec/apache2...

    file /usr/libexec/apache2/mod_xsendfile.so 
    /usr/libexec/apache2/mod_xsendfile.so: Mach-O 64-bit bundle x86_64
    

    Just to double-check that this is the problem you can also look at the httpd (apache) binary:

    file /Applications/XAMPP/xamppfiles/bin/httpd
    /Applications/XAMPP/xamppfiles/bin/httpd: Mach-O universal binary with 2 architectures
    /Applications/XAMPP/xamppfiles/bin/httpd (for architecture i386):   Mach-O executable i386
    /Applications/XAMPP/xamppfiles/bin/httpd (for architecture ppc):    Mach-O executable ppc
    

    Well now, that certainly will not work with an apache instance built without an x86_64 image. Trust, but verify, eh!

  3. Now that I'm certain I understand the issue, let's re-build the .so with the proper architecture forced on the apxs command line. To do that I'm just adding two new params, Wl (linker flags) and Wc (compiler flags). The -i means 'install' (move .so into the modules directory) and the -a means 'activate' (add or re-enable LoadModule line in the httpd.conf)

    sudo apxs -cia -Wl,"-arch i386" -Wc,"-arch i386" mod_xsendfile.c
    
  4. re-check that our new .so supports an architecture that matches the Apache installed (i386, not x86_64)

    file /Applications/XAMPP/xamppfiles/modules/mod_xsendfile.so
    /Applications/XAMPP/xamppfiles/modules/mod_xsendfile.so: Mach-O bundle i386
    

    Awesome. Now then, copy this turkey into the XAMPP install dir:

    sudo cp /usr/libexec/apache2/mod_xsendfile.so /Applications/XAMPP/xamppfiles/modules/
    

    And add the LoadModule line to the /Applications/XAMPP/xamppfiles/etc/httpd.conf.

    LoadModule xsendfile_module modules/mod_xsendfile.so
    

    You should be able to fire up the server using either the UI or the apachectl script found in the xamppfiles/bin directory.

Hope that helps you.

Also, I did a pretty decent due-diligence search and found just about squat looking for 'XAMPP X-SendFile cannot create object' in the Goog. What I did find was your question here, once I eliminated the 'XAMPP' since I was searching for 'XAMPP', not 'MAMP'

I started out with the 'x'AMP stack something like 10 years back using LAMPP, then WAMPP but the ApacheFriends guys call theirs XAMPP now for all of the platforms they support. I prefer using theirs since I know if I have to set up on a Windows server I can just download the same package that I use now but for Windows and I can expect to find all of the same servers installed without (too many) surprises.


So, just to be (very) thorough, the other way to discover these types of problems more easily is via Console.app. Open that up, filter on org.apache.httpd and you should see something similar to this:

httpd: Syntax error on line 117 of /private/etc/apache2/httpd.conf: Cannot load
/usr/libexec/apache2/mod_xsendfile.so into server:
dlopen(/usr/libexec/apache2/mod_xsendfile.so, 10): no suitable image found.
Did find:\n\t/usr/libexec/apache2/mod_xsendfile.so: mach-o, but wrong architecture

You can also get that from a command line when you start the apache server manually:

sudo apachectl -E /tmp/foo.txt -k start; tail -f /tmp/foo.txt 
1
naabster On

This worked for me:

  1. Install mod_xsendfile according to this for the default OsX Apache server.
  2. copy /usr/libexec/apache2/mod_xsendfile.so to /Applications/MAMP/Library/modules/
  3. Edit the Mamp httpd.conf file and add this line: LoadModule xsendfile_module modules/mod_xsendfile.so
  4. Restart Mamp