Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Installing X-Sendfile on Mac OS X Yosemitee

Installing mod_xsendfile on Mac OS X (Yosemite) [Update: El Capitan]

Update: El Capitan follows the same procedures, but you may have some difficulty with the compile/install, see the secation at the bottom for specific help with El Capitan

Installing mod_xsendfile for apache is atually quite simple, however I could find very little documentation out there. Here's my attempt to help out. In order to proceeed you'll need:

First lets go ahead and download the source code repository

cd ~/Desktop && git clone xsendfile && cd xsendfile

Now we only need to compile the module:

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

(See troubleshooting if you get a missing directory error). If you're using the stock apache that ships with Yosemite you should be done at this point, the install script automatically adds the LoadModule line to your httpd.conf. Just restart apache, feel free to delete the xsendfile directory on your desktop as well.

Note: Typically you'll need to turn it on by adding these apache directives to a httpd.conf, VirtualHost, or .htaccess:

XSendFile on
XSendFilePath /absolute/path/to/files

(XSendFilePath cannot be placed in your .htaccess)


Missing Compiler Directory

If you're like me you'll run into an issue with a missing directory. Apple has made a "woopsies" and its configuration tool "apr-1-config" returns a directory that doesn't exist. I recieved this error:

/Applications/ No such file or directory

The files the compiler is looking for do exist, but they are (likely) in this a directory named "XcodeDefault.xctoolchain" rather than "OSX10.10.xctoolchain". A quick symlink fixes this bug:

sudo ln -s /Applications/ /Applications/

Finally, we just need to run that compile command again.

Slow Files

Although xsendfile worked with the above steps, mine were taking over five seconds to load. A quick apache directive, and restart fixed my issue:

EnableSendfile off

Note: EnableSendfile's default value is supposed to be off, but for some reason that wasn't cutting it.

Update: El Capitan

The above steps are accurate for installing El Capitan, but a few locations will need to be linked/included in order to properly compile. In addition, because Apple now restricts all access (even root access) to "system" directories, you'll need to install the final module manually. First lets deal with the symlinks:

My compiler was complaining that it couldn't find apr.h (and other apr files). Turns out it was looking for them here:


however, that directory doesn't exist. There was no MacOSX10.11.Internal.sdk intead the directory was MacOSX10.11.sdk. So to create a symlink:

ln -s /Applications/ /Applications/

Even after that the compiler had a heck of a time resolving a whole bunch of other dependencies like Availability.h and httpd.h. You those files exist, but they are just in slightly different locations. Since this is a one-time compile for me, I just manually linked up lots of those directories using the apxs -I flag. Here was my final compile command:

sudo apxs -cia -Wc,"-arch i386 -arch x86_64" -Wl,"-arch i386 -arch x86_64" -I "/Applications/" -I "/Applications/" mod_xsendfile.c

This command was able to make it all the way through the compile phase, but the libtool was unable to perform the final installation:

install: /usr/libexec/apache2/ Operation not permitted

This is because of Apple's new SIP policy. No worries though, you'll find the file in a hidden directory in your compile directory:


To install I created a new directory under /usr/local/ (which Apple does allow). Create this directory:

mkdir /usr/local/libexec/apache2
cp .libs/ /usr/local/libexec/apache2/

I then chose to manually reference this location in my httpd.conf file (sudo nano /etc/httpd/httpd.conf):

LoadModule xsendfile_module /usr/local/libexec/apache2/

great thanks

brki commented Oct 2, 2015

I see on OS X 10.11 that the file can't be installed in the directory /usr/libexec/apache2 due to a restricted flag on the /usr/libexec/apache2 directory. mentions a couple of ways to work around this. I wonder if there's some other, easier way to work around this?


justin-schroeder commented Oct 31, 2015

@brki you can see my update on this file for El Capitan, but essentially, you can manually install the in another location and then manually reference that location with your LoadModule statement in your httpd.conf file. I chose to place it and reference it here:

LoadModule xsendfile_module /usr/local/libexec/apache2/

joshuabryant commented Jan 10, 2018

Hey, @justin-schroeder. Just ran through this for MacOS High Sierra, and it went super smooth.

I forked and updated the documentation for future users:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment