Monday, 7 February 2011

Running IIS and Apache on the same Windows 2008 R2 Server

I’m trying to get a Composite C1 site and the Apache WebDAV front-end to Subversion running on the same Windows 2008 R2 server, and doing so requires a bit of trickery with IP address bindings and such, and I thought I’d share it – partly ‘cos it’s useful, and partly because I’m bound to have to do this again in three months time and there’s no way I’ll remember how I did it. First off, make sure your box has (at least) two IP addresses – I’ve bound mine to 192.168.0.13 and 192.168.0.14
To get IIS to listen on ONLY 192.168.0.13, you’ll need to run the netsh.exe utility.
C:\Users\dylan.beattie>netsh
netsh>http add iplisten ipaddress=192.168.0.13
IP address successfully added
netsh>http show iplisten
IP addresses present in the IP listen list:
-------------------------------------------
    192.168.0.13
netsh>exit
(note that netsh.exe is a Windows 2008 utility – if you’re running Windows 2003 or earlier, look up the docs on using httpcfg.exe to achieve the same thing)
If you now fire up a web browser and go to http://192.168.0.13/, you should get the default IIS7 “Welcome” screen, and http://192.168.0.14/ shouldn’t return anything at all. Now to get Apache listening on 192.168.0.14. Find your httpd.conf file – if you’ve just installed CollabNet Subversion (like I have) it’ll be in the \data\conf folder of wherever you put your SVN install.
You’ll need to find the Listen directive in httpd.conf, and modify it to say:
Listen 192.168.0.14:80
That’s all. Next time – to get Git running on the same Apache installation… until then, happy hacking.

UPDATE: After running this for several years, I've found that occasionally, following an unscheduled shutdown or power outage, IIS won't come back up properly after the box is restarted. Sites will respond on http://localhost/ but trying to access them via hostname gives an ERR_CONNECTION_RESET message.
This can be fixed by removing and re-adding the HTTP binding:
C:\>netsh
netsh> http
netsh http> delete iplisten 192.168.0.13netsh http> add iplisten 192.168.0.13netsh http> exit

C:\>iisreset

3 comments:

Anonymous said...

THANKS!!!

Amar pawar said...

very helpful....but I changed the IIS and apache port without using commands ....i followed this tutorial - http://www.superpctricks.com/2013/11/running-iis-and-apache-on-same-server.html

Dylan Beattie said...

If you can run them on different ports, it's much more straightforward. My problem was I needed them both listening on port 80.