Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

10.5: Use Apache virtual hosts outside the Sites folder Internet
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
  1. Set up your virtual host with ~/Documents/any/sub/folder/ as the document root. (see Apache manual)
  2. Add yourself to the www group: sudo dscl localhost append /Local/Default/Groups/www GroupMembership _username_ -- replace _username_ with your user's short username.
  3. chgrp www ~/Documents
  4. 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.
    •    
  • Currently 1.93 / 5
  You rated: 3 / 5 (14 votes cast)
 
[16,258 views]  

10.5: Use Apache virtual hosts outside the Sites folder | 8 comments | Create New Account
Click here to return to the '10.5: Use Apache virtual hosts outside the Sites folder' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.5: Use Apache virtual hosts outside the Sites folder
Authored by: arcticmac on Jun 11, '09 09:45:49AM

Seems like a good use for ACLs...



[ Reply to This | # ]
10.5: Use Apache virtual hosts outside the Sites folder
Authored by: tackyy on Jun 11, '09 11:59:42AM

I put my virtual host site roots in /Library/Webserver/Documents. After I create the directory I have to chown it to the user I'll be logged in as while working on that site (never roll as an admin for your day-to-day user!). That solves the problem of having permissions you don't want in your users home directory.



[ Reply to This | # ]
10.5: Use Apache virtual hosts outside the Sites folder
Authored by: gdhnz on Jun 11, '09 12:56:15PM

1. From memory, the web user and group are both _www in 10.5. It was changed from www in 10.4.

2. Why not assign the web usergroup to your homedir?

# chown -R :_www ~/Documents

Then just set permissions based on the group. From memory, if "x" isn't present, you can't navigate into directories.

3. Why not use /Library/Webserver for all your snippets etc and /Library/WebServer/Documents for your web accessible stuff? A lot safer than changing permissions on your homedir. There's also the option of creating symbolic links and/or apache aliases.



[ Reply to This | # ]
10.5: Use Apache virtual hosts outside the Sites folder
Authored by: enthooz on Jun 11, '09 09:26:59PM

The group is indeed '_www'. Running 'chgrp www' on a directory effectively changes group ownership to '_www'. Granted, it would have been more precise to included the underscore. Likewise, my wording was pretty shabby in the post -- it was late and I had been racking against this issue for awhile. :)



[ Reply to This | # ]
10.5: Use Apache virtual hosts outside the Sites folder
Authored by: enthooz on Jun 11, '09 09:45:13PM

Additionally, in this case -- for a reason unknown to me -- it's not required that the assignment of group permissions be recursive. Weird, right?

FYI, 'chgrp _group_' is the same as 'chown :_group_'

The symlinks idea -- that's a good one. For some reason, I dismissed that at first. But, I think it might be the best direction to follow.

Thanks.



[ Reply to This | # ]
10.5: Use Apache virtual hosts outside the Sites folder
Authored by: boxcarl on Jun 11, '09 09:14:58PM

This hint is overly complicated. Just make a symbolic link from /Library/WebServer/Documents to ~/Sites. ~/Sites already has the right permissions set, out of the box, and using "fix permissions" on your disk or upgrading to a new Mac won't screw it up.

If you want to host multiple sites, just make the symlink point to ~/Sites/localhost and then rename the sub-folder in your Sites directory to "localhost" when you want to change what site you are serving.



[ Reply to This | # ]
10.5: Use Apache virtual hosts outside the Sites folder
Authored by: enthooz on Jun 11, '09 09:39:20PM

Virtual hosts are a method of serving multiple sites without the need to change directory names, especially when using name based virtual hosting. So one could easily have multiple directories inside the ~/Sites folder and point individual virtual hosts at each of these sites. By updating /etc/hosts or /private/etc/hosts, your system can be configured so that typing 'apple' or 'baboon' or whatever name you choose points to different vhosts (sites) on your machine. I was just looking for a way to get out of being confined to keeping the sites I'm serving in either /Library/WebServer or /Users/*/Sites. In OS X, it seems like the best option is keeping web projects in Sites and using symlinks to easily access them from elsewhere. I suggest looking into name based virtual hosts to avoid the hassle of renaming folders.



[ Reply to This | # ]
10.5: Use Apache virtual hosts outside the Sites folder
Authored by: RickMacEldery on Sep 06, '09 01:10:47PM

Well this may not be the solution you are looking for but might put you on the right path:

Instead of using virtual host directive, use the default to localhost.

The first vh block is used for the default localhost, comment everything out. More like an empty virtualhost block.
<virtualhost *:80>
# Document Path "/leave it blank or comment it out with #"
#ServerName leave it blank or comment it out with #
</virtualhost>
By leaving these commented out apache will use documentroot path in the httpd.conf file. (this is the default) for localhost and any unresolved uri's.

change and edit documentroot as need.

standard permission applies... and make sure safe mode in php is off if you are using php.

Hope this helped.
rickmacelderry



[ Reply to This | # ]