Setting up subdomains in apache win32

I only started to do this the other day and found it saves loads of time. I don't know why I didn't do this years ago!

What you'll need to do

  • update apache config
  • update iss config (if using port 80 and iss is running)
  • amend host file enteries

Updating your apache config

Open your httpd.conf apache config file and find the ServerName directive, add (or uncomment) the NameVirtualHost directive and add a couple of virtual hosts.
BTW, my machine name is 'nineinchnails' in this example.

Then you'll need to add the Directories or they won't have the correct permissions

# add to your httpd.conf file

NameVirtualHost *

<VirtualHost *>
  ServerName subone.localhost
  ServerAlias subone.nineinchnails
  DocumentRoot C:/web/one
</VirtualHost>

<VirtualHost *>
  ServerName subtwo.localhost
  ServerAlias subtwo.nineinchnails
  DocumentRoot C:/web/two
</VirtualHost>

# Directories 

<Directory "C:/web/one">
    Options Indexes FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>
<Directory "C:/web/two">
    Options Indexes FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>

Update IIS config if your going to use port 80

Set IIS to listen to port a different port e.g. 8082 if your going to run apache on port 80.

Amend your host file

Amend your hosts file, it's normally in C:/WINDOWS/system32/drivers/etc

# add lines to your host file for your new subdomains with the format:
# IP  subdomain.locallost
# IP  subdomain.machinename 
# For example:

127.0.0.1       subone.localhost
127.0.0.1       subone.nineinchnails
127.0.0.1       subtwo.localhost
127.0.0.1       subtwo.nineinchnails