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:
- XCode intstalled including the "command line tools" (http://railsapps.github.io/xcode-command-line-tools.html)
- Source code (https://github.com/nmaier/mod_xsendfile)
- Apache 2.4 installed (comes with yosemite by default)
First lets go ahead and download the source code repository
cd ~/Desktop && git clone [email protected]: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)
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.
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.
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
great thanks