Local Development Setup Pt 3: Virtual Directories in Apache

In a previous post we touched upon the Alias statement in your VirtualHost directives. An Alias is a way of defining a virtual directory for your site. This is a pretty common practice in the web world. Your site code may be stored in your site's root (wwwroot) folder, but you may want to store your assets (images, video, stylesheets, etc.) outside your webroot. You might even want to store them on another server altogether. You'll want to access these items as if they're part of your site, like http://username.companyname.loc/Images/mypic.jpg or http://username.companyname.loc/Media/myvideo.flv.

Defining an Alias is easy, when dealing with your local file system. An Alias that points to a UNC path, in Windows, is another story. You have to use a UNC path because Apache will not allow you to utilize a mapped drive (it'll crash Apache, at least under 2.0). What took me a while to figure out was that you can not use Apache to control the directory access (as in permissions), you must do this through the user account access. You can not use the Directory Apache directives for access control. This also means that your Apache instance must run as the user who has access to the remote resource (I also setup CF instance to run as the same user).

I also discovered something else the hard way, Apache Aliases are case-specific. This means that you have to use double Aliases for each virtual directory that you define via an Alias. Remember, this is Windows, so code can go either way. You'll want to plan for either eventuality.

In our last post we defined a 'sites' instance, for the display of a mythical, templated application system. So, imagine that each site of that system would require it's own VirtualHost directive. Each one, though, would also be using shared media resources from the same location outside the webroot, like on a media server. For this, you can create another include in your Apache conf folder - site_aliases.conf, within which you could singularly define your remote virtual directories:

Alias /Images/ //remote-serv1/Inetpub/wwwroot/Images/
Alias /images/ //remote-serv1/Inetpub/wwwroot/Images/
Alias /Video/ //remote-serv1/Inetpub/wwwroot/Video/
Alias /video/ //remote-serv1/Inetpub/wwwroot/Video/
Alias /Styles/ //remote-serv1/Inetpub/wwwroot/Styles/
Alias /styles/ //remote-serv1/Inetpub/wwwroot/Styles/
Alias /SiteSpecific/ //remote-serv1/Inetpub/wwwroot/SiteSpecific/
Alias /sitespecific/ //remote-serv1/Inetpub/wwwroot/SiteSpecific/

Once you've defined these remote shared resources, you can then Include them in your site definitions in your VirtualHost directives:

<VirtualHost 127.0.0.1:80>
   ServerAdmin username@companyname.com
   # Root folder for thisdomain.com, in the 'sites' instance
   DocumentRoot "C:\Documents and Settings\username\My Documents\wwwroot\siteroot"
   ServerName *.thisdomain.loc
   # SGB [072007]: shared Alias Include
   Include conf/site_aliases.conf
   ErrorLog logs/thisdomain.loc-error.log
   CustomLog logs/thisdomain.loc-access.log common
   # SGB [072007]: Add include for the 'sites' ColdFusion instance
   Include conf/cf_sitesinstance.conf
</VirtualHost>

Once you've restarted your Apache instance you will be able to access these resources as part of the domain.

Comments
Luke's Gravatar Nice article, but fonts on your site are always so hard to read. I have default browser settings (FireFox: View->Text Size->Normal) and I can't read the code examples on your site. I always have to increase font size just for blog.
# Posted By Luke | 7/23/07 7:32 PM
Cutter's Gravatar Thanks for the heads up Luke, and the kudos. I'm using a pretty vanilla adjustment of the standard BlogCFC stylesheets, but I just adjusted an item for nested anchor tags in the 'code' blocks. I don't think I'm seeing the same thing, and I'm using a standard FF install, but I'll check it on a few other systems as well. Biggest place I've had 'style' issues is in my RSS reader in Thunderbird.

Oh well, work in progress:)
# Posted By Cutter | 7/24/07 9:46 AM
Aaron West's Gravatar Luke's right Cutter, the blog posts are hard to read, but the code blocks are impossible to read without adjusting the font in Firefox. Come look at my machine and I'll show you (Mac and PC).
# Posted By Aaron West | 8/13/07 3:22 PM
Scott P's Gravatar If you get a chance - can you add this css fix for us mac users:
http://www.coldfusionjedi.com/index.cfm/2007/7/26/... tant-Update-for-BlogCFC-Users

thanks
# Posted By Scott P | 12/1/07 8:02 PM
BlogCFC v. 5.8.001 was created by Raymond Camden. Layout inspired by bluerobot.com., with some JQuery thrown in for fun.