Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@justin-schroeder
Last active August 10, 2018 19:54
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save justin-schroeder/d3ef404e80a7ae658a8d to your computer and use it in GitHub Desktop.
Save justin-schroeder/d3ef404e80a7ae658a8d to your computer and use it in GitHub Desktop.
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 git@github.com:nmaier/mod_xsendfile.git 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)

Troubleshooting

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/Xcode.app/Contents/Developer/Toolchains/OSX10.10.xctoolchain/usr/bin/cc: 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/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.10.xctoolchain

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 mod_xsendifle.so 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:

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.Internal.sdk/usr/include/apr-1

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/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.Internal.sdk

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/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include" -I "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include/apache2" 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/mod_xsendfile.so: 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:

.libs/mod_xsendfile.so

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

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

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/mod_xsendfile.so

@douglasdeodato
Copy link

great thanks

@brki
Copy link

brki commented Oct 2, 2015

I see on OS X 10.11 that the mod_xsendfile.so file can't be installed in the directory /usr/libexec/apache2 due to a restricted flag on the /usr/libexec/apache2 directory.

http://apple.stackexchange.com/a/202969/149592 mentions a couple of ways to work around this. I wonder if there's some other, easier way to work around this?

@justin-schroeder
Copy link
Author

@brki you can see my update on this file for El Capitan, but essentially, you can manually install the mod_xsendfile.so 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/mod_xsendfile.so

@joshuabryant
Copy link

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: https://gist.github.com/joshuabryant/512618a06c677ea06b431f8c025cb2cc

@jbis9051
Copy link

/usr/local/opt/apr/libexec/build-1/libtool: line 1749: /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.12.xctoolchain/usr/bin/cc: No such file or directory
apxs:Error: Command failed with rc=65536
.

Solution:

sudo ln -s /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.12.xctoolchain/usr/bin/cc

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