Named Virtual Hosts
I don't know why but I've never bothered setting up named virtual hosts for local development. I've generally just used multiple ColdFusion instances on different ports or multiple Apache listeners (and port-based virtual hosts). I guess that was related to the type of development I was doing (working for a corporate and thus focused on just one big project at a time).
Today I decided that my Apache setup was less than ideal and took the plunge and reconfigured everything to use named virtual hosts instead. It went pretty smoothly because all I did was:
- Replace existing Alias directives with VirtualHost groups (and copy in any associated Directory group)
- Changed each port-based VirtualHost group to use *:80
- Added appropriate ServerName directives with made up domain names
- Added those domain names to /etc/hosts
- Restarted Apache (sudo apachectl restart)
Now I can hit dev.corfield.org or dev.fuseboxframework.org or whatever and get the site I expect. Nice. Why didn't I do this sooner?
The only roadblock I hit was that I drew a complete blank on how to enable directory listings (for my local "scratch" ColdFusion instance). I had
Options Indexes enabled everywhere but no dice, just "403 Forbidden". I could browse directories on my main document root but couldn't browse directories on any of my ColdFusion domains. I thought it was something deep inside an XML file. After bashing my head against a wall for about half an hour I asked a few folks online. They didn't know. So I did what I should have done in the first place: I asked on the
#coldfusion channel on irc.dal.net. Sure enough, within a few minutes I was up and running. Thanks go to B0llock5 for that!
The solution? To add the following directives to the
VirtualHost that needed directory browsing:
- Order Allow,Deny
- Allow from All
I knew this really so I just felt dumb for blanking on it. Duh!
Tags: apache · coldfusion
25 responses so far ↓
1 Damon Gentry // Apr 11, 2007 at 5:21 PM
adam.project.net --> /users/adam/projects/xxxx
cindy.project.net --> /users/cindy/projects/xxxx
And, if you have the capacity, you can give each developer their own JRun server. Check-ins (or commits) can then be copied (via Ant or some alternative) to the integration directory.
dev.project.net --> /web/int/projects/xxxx
2 Ouz Demirkap1 // Apr 11, 2007 at 5:54 PM
I also would suggest to use XAMPP (apachefriends.org) which has PHP, MySQL and some other useful stuff beside Apache.
And here some other ideas for an efficient development platform:
http://demirkapi.net/avblog/permalinks/2005/11/22/Development%2DPlatform%2D%2D%2D1/
3 Jeff Self // Apr 11, 2007 at 6:44 PM
Since I develop with multiple web technologies, I don't want the jrun_module all the time on my MacBook Pro. So I put the JRun module and settings inside of each virtual host that requires ColdFusion.
4 SeanG // Apr 11, 2007 at 7:42 PM
I did have one client that insisted on having everything set up to use relative addressing relatively recently (no pun intended), however this is how they had set up their production environment.
I guess the moral of the story..... mimic production as much as possible, even if it does mean editing your host and apache config files as time goes on.
5 Kurt Wiersma // Apr 11, 2007 at 7:46 PM
JRunConfig Verbose false
JRunConfig Apialloc false
JRunConfig Ignoresuffixmap false
JRunConfig Bootstrap 127.0.0.1:51000
Replace porst 51000 with the proxy port for the cf instance oyu want. I usually have a default instance which I define at the top of my apache config.
6 Sammy Larbi // Apr 11, 2007 at 8:06 PM
7 Sean Corfield // Apr 11, 2007 at 10:23 PM
@Oguz and Sammy - interesting... never occurred to me to use completely bogus domain names!
@Kurt - thanx for the tips on multiple instances and multiple named virtual hosts.
8 Spike // Apr 11, 2007 at 11:08 PM
<VirtualHost 127.0.0.1>
VirtualDocumentRoot C:/webapps/%0/www/
</VirtualHost>
As long as I have a directory under C:/webapps/ that has the same name as the domain name (or IP address) in the browser, I don't need to add anything else to my Apache config file. I also don't need to stop and restart Apache if I add an entry to my hosts file. It automatically works as long as there is a directory to match the domain. I don't remember the last time I even looked at my Apache config file to be honest, and I have about 9 projects that are new in the last 6 months.
9 Christoph Schmitz // Apr 11, 2007 at 11:58 PM
So I have cf5.procept.net, cf61.procept.net, cf70.procept.net, bd.procept.net, and, railo.procept.net. All virtual hosts use the same document root directory. In case I want to test something agains a different app server, I just change the URL.
Plus I have virtual hosts for my biggest clients for which I do corporate intranet development.
10 Tero Pikala // Apr 12, 2007 at 12:36 AM
Saves you trouble of modifying hosts file every time...
11 Tom Chiverton // Apr 12, 2007 at 1:03 AM
12 Dan Wilson (B0ll0ck5) // Apr 12, 2007 at 7:19 AM
dw
13 Ken Dunnington // Apr 12, 2007 at 7:58 AM
14 Dave Shuck // Apr 12, 2007 at 8:41 AM
15 William from Lagos // Apr 12, 2007 at 10:39 AM
16 dickbob // Apr 12, 2007 at 12:38 PM
Any thoughts?
17 Sean Corfield // Apr 12, 2007 at 1:58 PM
Include /private/etc/httpd/users/*.conf
to include the conf file for each individual user.
18 Dave Shuck // Apr 12, 2007 at 2:05 PM
So pretty much... umm... forget what I said. :)
19 Spike // Apr 12, 2007 at 2:14 PM
Try adding an Alias:
Alias /CFIDE C:/CFusionMX7/wwwroot/CFIDE
I use the standard port 8500 URL to access the CF adminstrator, so I don't know if you'll also need to add any <Directory> or <Location> directives. My guess is that you'll need a <Directory> directive something like this:
<Directory C:/CFusionMX7/wwwroot/CFIDE>
Order allow,deny
Allow from all
</Directory>
For local development you should be able to put the Alias and <Directory> outside the VirtualHost. That way it will apply to all virtual hosts including any that don't use the standard VirtualDocumentRoot.
20 dickbob // Apr 12, 2007 at 2:43 PM
Previous to your suggestion I had loads of...
<VirtualHost *>
DocumentRoot /Users/dickbob/Sites/foo/www
ServerName foo
Alias /CFIDE /Library/Apache2/htdocs/CFIDE
</VirtualHost>
...entries, one for each site but now have one...
<VirtualHost 127.0.0.1>
VirtualDocumentRoot /Users/diskbob/Sites/%0/www
Alias /CFIDE /Library/Apache2/htdocs/CFIDE
</VirtualHost>
...which works find for all my sites until I try and hit the CFMX Admin on...
http://localhost/cfide/administrator/index.cfm
...when it starts to complain...
"File not found: /cfide/administrator/index.cfm"
I've tried add another entry after my new one...
<VirtualHost *>
DocumentRoot /Library/Apache2/htdocs
ServerName localhost
</VirtualHost>
...but it doesn't seem to cure the problem.
I just need some way of saying "use VirtualDocumentRoot for all sites except localhost".
Hummm, I'm still new to this Apache stuff.
21 Sean Corfield // Apr 12, 2007 at 3:40 PM
22 Spike // Apr 12, 2007 at 3:55 PM
As Sean mentioned, Apache is case sensitive. Putting in an Alias for both /CFIDE and /cfide should get around most of the issues you're likely to run into.
23 dickbob // Apr 15, 2007 at 8:44 AM
@Spike, that's a neat idea I'll use that as well, thanks.
24 Raymond Camden // May 15, 2007 at 6:41 AM
25 Raymond Camden // May 15, 2007 at 8:02 AM
Leave a Comment