2008
04/07
23:09

Compiling mod_xsendfile for OS X

Today I needed to compile mod_xsendfile for OS X on Intel. The standard command for this,

apxs -cia mod_xsendfile.c

resulted in a module that was for i386 only.

Apache on Leopard (untested on Tiger) doesn’t appreciate this, throwing this error:

4/7/08 5:08:08 PM org.apache.httpd[ 15990] httpd: Syntax error on line 116 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

Turns out the solution is pretty simple. Just change the command to apxs to this:

apxs -cia -Wc,"-arch x86_64 -arch ppc -arch i386 -arch ppc64" -Wl,"-arch x86_64 -arch ppc -arch i386 -arch ppc64" mod_xsendfile.c

This will generate a fat-binary for all four current Mac architectures.

comments

add comment
by christian; 2008-apr-08 10:06

thanks!

by Oliver; 2008-apr-21 01:45

Would you happen to know how to compile it within a MAMP environment. I can’t figure it out. Thanks

by tm; 2008-apr-21 04:20

You do need to have Xcode installed first. Then, the command at the bottom of the post should be all that is necessary. That will compile for Apache and PHP as shipped by Apple.

If you’ve installed your own Apache using macports or something, just make sure you point to the macports (or whatever) version of apxs.

by Kevin; 2008-may-01 01:37

Many thanks! I’ve been searching for this solution for days.

by Gerrit Kaiser; 2008-oct-21 03:47

thanks a lot, saved time!

add comment