Apache, Virtual Hosts, PHP, CF5 and CFMX (part 1)

Posted by Mark Drew on code on June 7, 2004

Tagged under webdev

Web development sometimes can be a right pickle. If you have been working for few different sites you start to get conflicts of technology or you start buying computers for the sake of running one environment per computer, NOT economic!

Take my current setup for example, I am doing development of a site in Coldfusion MX, support of another site based on Coldfusion 5 and development of another site based on PHP. To sort all these things out I use something called Virtual Hosts. The concept of a Virtual host is that of hosting a number of websites on one single server, most probably using a single IP address and using the URL (domain) name that is requested to display the chosen website.

In my setup I use Apache(2.0.49) and have implemented the virtual hosts for each of the projects that I am working on, e.g.:

http://cf5_project/ which would point to c:/www/cf5_project , http://cfmx_project which would point to c:/www/cfmx_project and http://php_project which would point to c:/www/php_project

For each of these projects I have a slightly different setup and it is achieved as follows:

Add entries in the hosts file To achieve this you need to edit the hosts file which can be found in: C:\WINNT\system32\drivers\etc\hosts

and add the following lines.

127.0.0.1 cf5_project 127.0.0.1 cfmx_project
127.0.0.1 php_project

of course, replacing WINNT for your system path, if you are using OS X you can use NETINFO manager under Applications/Utilities to add an entry (duplicate localhost and change the name)

Enable and add the Virtual Hosts in Apache Now that you have done that, you need to change the configuration of Apache by editing the httpd.conf file

If you look at the bottom of the httpd.conf file you will see an entry such as:

# Use name-based virtual hosting. #NameVirtualHost *:80

Remove the # so that you can add a few more entries as follows:

# Use name-based virtual hosting. NameVirtualHost cf5_project NameVirtualHost cfmx_project NameVirtualHost php_project

Now that you have told apache which domain names it hosts, we can now defined each one with its different settings. To do this, add entries for each project below the NameVirtualHost entries.

<VirtualHost cf5_project> ServerAdmin [email protected] DocumentRoot "c:/www/cf5_project" ServerName cf5_project ErrorLog logs/cf5_project-error_log CustomLog logs/cf5_project-access_log common </VirtualHost>

Note the changes in bold. The first one, next to “VirtualHost” should match the NameVirtualHost you added previously. Change the DocumentRoot attribute to point to your project’s root directory, add the ServerName the same as the NameVirtualHost and then setup the name of the log files to which errors and access requests will be logged to.

Repeat this process for cfmx_project and php_project.

Adding the individual modules For each project I have a different server assigned, for coldfusion 5 you need to download (and follow the install instructions) available from http://home.nextron.ch/coldfusion

then I modified the entry for cf5_project as follows:

<VirtualHost cf5_project> ServerAdmin [email protected] DocumentRoot "c:/www/cf5_project/" ServerName cf5_project ErrorLog logs/cf5_project.local-error_log CustomLog logs/cf5_project.local-access_log common #Coldfusion 5 module LoadModule coldfusion_module modules/mod_coldfusion.so AddHandler type-coldfusion cfm dbm </VirtualHost>

Once this runs we can then go on and set up CFMX as another Virtual Host.

to be continued…




comments powered by Disqus