Update 1: El Capitan follow the same procedures, but you may have some difficulty with the compile/install, see the section at the bottom for specific help with El Capitan.
Update 2: Same procedures for High Sierra. Only complication was Slow Files (which is documented in the troubleshooting section).
Installing X-Sendfile for Apache is actually 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 installed 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, let's 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 received this error:
/Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.10.xctoolchain/usr/bin/cc: No such file or directory
The files that the compiler is looking for do exist, but they are (likely) in 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 X-Sendfile 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
. 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
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