Apache HTTP Server on OS X Yosemite - shawfdong/hyades GitHub Wiki
OS X Yosemite (10.10) comes with the Apache HTTP Server 2.4.16:
$ uname -a Darwin corsica3.ucsc.edu 14.5.0 Darwin Kernel Version 14.5.0: Tue Sep 1 21:23:09 PDT 2015; root:xnu-2782.50.1~1/RELEASE_X86_64 x86_64 $ apachectl -v Server version: Apache/2.4.16 (Unix) Server built: Jul 22 2015 21:03:09
but the web server is disabled by default (/System/Library/LaunchDaemons/org.apache.httpd.plist):
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>Disabled</key> <true/> <key>Label</key> <string>org.apache.httpd</string> <key>EnvironmentVariables</key> <dict> <key>XPC_SERVICES_UNAVAILABLE</key> <string>1</string> </dict> <key>ProgramArguments</key> <array> <string>/usr/sbin/httpd</string> <string>-D</string> <string>FOREGROUND</string> </array> <key>OnDemand</key> <false/> </dict> </plist>
I recently enabled the Apache HTTP Server on Prof. Doug Lin's Mac Pro, so that he can server his course materials from http://corsica3.ucsc.edu/~lin/.
Per-user web directory is disabled by default[1]. To enable it, uncomment the following 2 lines of /private/etc/apache2/httpd.conf:
LoadModule userdir_module libexec/apache2/mod_userdir.so Include /private/etc/apache2/extra/httpd-userdir.conf
On OS X, the default per-user web directory is Sites; but Prof. Lin prefers public_html. Modify /private/etc/apache2/extra/httpd-userdir.conf so that it reads as follows:
UserDir public_html Include /private/etc/apache2/users/*.conf
And create a file /private/etc/apache2/users/lin.conf with the following content:
<Directory "/Users/lin/public_html/"> Options Indexes AllowOverride None Require all granted </directory>NOTE Require all granted is an access control configuration for Apache 2.4[2], which is equivalent to the following configuration for Apache 2.2:
Order allow,deny Allow from all
We can test whether the web server is working, by manually start the HTTP server:
$ sudo apachectl startand pointing our web browser to http://corsica3.ucsc.edu/~lin/.
To enable the web server permanently (to survive reboots):
$ sudo launchctl load -w /System/Library/LaunchDaemons/org.apache.httpd.plistNOTE This command doesn't modify /System/Library/LaunchDaemons/org.apache.httpd.plist; rather, it adds the following lines to /private/var/db/com.apple.xpc.launchd/disabled.plist:
<key>org.apache.httpd</key> <false/>