10.5: Use Apache virtual hosts outside the Sites folder
Jun 11, '09 07:30:00AM
Contributed by: enthooz
I want to run Apache with virtual sites located outside my user's Sites folder. Instead, I wanted to be able to keep them anywhere within my user's Documents folder. This is because sibling directories of the desired document root may be assets, documentation, various source code, and/or any content related to the project. I do not wish to keep these files in a web-accessible folders, but I do want to keep these directories in the same parent directory.
I scoured the net and it seems that I may be the only one who wishes to do this. Just in case I'm not, though the following is how I figured it out.
The following solution worked for me in OS X 10.5.6 running Apache 2.2.9. Note that if you don't understand any of the following steps, please use caution and Google before proceeding
- Set up your virtual host with ~/Documents/any/sub/folder/ as the document root. (see Apache manual)
- Add yourself to the www group: sudo dscl localhost append /Local/Default/Groups/www GroupMembership _username_ -- replace _username_ with your user's short username.
- chgrp www ~/Documents
- chmod 750 ~/Documents
I'm not entirely comfortable with enabling +rx access to the www group, and therefore the httpd process on my home directory. However, this is a local development machine and I'm stoked to at least maintain my usual linux directory structure and have my vhosts working.
Please, if anyone knows of a better way to allow Apache to use any folder as the document root for a virtual host -- without enabling read/execute access to www group on one's home directory -- do inform.
Comments (8)
Mac OS X Hints
http://hints.macworld.com/article.php?story=200906100223537