Using Symlinks and Virtual Hosts to Serve Pages Outside of Sites Directory Using Apache on the MAC
I like keeping all my code and websites in a single “Code” directory on my machine, but it isn’t straightforward, from what I can tell, to get Apache on the MAC
to serve up pages anywhere outside of the default “Sites” directory that is created when you enable “Web Sharing” on the MAC.
After doing a lot of searching, I finally found a solution that works for me.
I doubt this is the only solution, or even the “proper” solution, but it seems to work.
Below are all the steps I took in order to serve pages out of directories other then those in the “Sites” directory. For these steps, I will assume there is an existing directory of “~/Code/MyWebSite” that has a simple “Hello World” index.html file in it.
Enable Web Sharing on the MAC by going to System Prefrences –> Sharing –> Check Enable Web Sharing
Edit your username.conf file located in /private/etc/apache2/users and add the “FollowSymLinks” directive
console
123456
<Directory "/Users/yourUserName/Sites/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
Edit the /private/etc/apache2/httpd.conf file and make sure the line under “# Virtual hosts” is not commented out, like so:
console
1
Include /private/etc/apache2/extra/httpd-vhosts.conf
Edit the /private/etc/apache2/extra/httpd-vhosts.conf file and add: