How to Run Apache and IIS at the Same Time: Part 2

By Craig Buckler

In part 1 of this article we discussed how Apache and IIS could be installed on separate real or virtual machines. However, that may not be practical if you’re the lead developer on a team of one. In this post, we discuss how you can install both servers on the same machine.

Simultaneous Servers

You can install Apache and IIS on the same Windows PC at the same time. Although the applications will run, they both listen for web requests on TCP port 80 — there will be clashes so a little configuration is required.

The easiest fix is to change the default port for one of the servers to 81 (or any other spare number). On Apache, you can change the Listen directive in the httpd.conf configuration file:

Listen *:81

On IIS, you change the Bindings setting in the IIS Manager:

IIS TCP port bindings

Microsoft provide a useful TCP port how-to page for all versions of IIS.

The browser URL will therefore be http://localhost/ for the server using port 80 and http://localhost:81/ for the server using port 81.

This method allows you to test the same application on different servers, although you may experience file locking or some other strange issues.

It’s a great solution but I don’t use it. The main reasons: I often forget to change the port when testing, the alternative port number can cause development complications, it’s rare that I need both servers at the same time, and I don’t like background programs running when I’m not using them. Fortunately, there is an alternative…

Server Switching

My preferred solution is to run whichever server I want when I need it. Apache and IIS are both launched as a Windows service — open Administrative Tools > Services. Locate Apache and IIS (W3SVC – World Wide Web Publishing Service) and set both Startup types to Manual:

IIS TCP port bindings

(Make a note of Apache’s service name — in the screenshot above, it’s “Apache2.2”.)

Neither server will run when your PC is booted. To start and stop the services, we’re going to create 4 batch (.bat) files in the same folder. Batch files are a list of command line instructions which have been around since the MS-DOS days:

This will stop IIS and start/restart Apache. (Note that ‘Apache’ is assumed to be the service name in the third line, but your installation may be different.)

@call stop-iis.bat
@call stop-apache.bat
@net start Apache

This will stop Apache (change the service name if necessary).

@net stop Apache

This will stop Apache and start/restart IIS.

@call stop-apache.bat
@call stop-iis.bat
@net start W3SVC

This will stop IIS on Windows Vista or 7.

@net stop was /y

This will stop IIS on Windows XP or earlier.

@net stop iisadmin /y

You can double-click these files to run them or create desktop / start menu shortcuts for easier access.

I hope you find one or both of those solutions useful. Do you have any other tips for running different web servers on the same PC?

  • robb1e

    I have literally just done this for a production server, except I had a .NET based and a Java application to run so I let Apache listen on port 80 and then use the virtual host directives to to proxy passing to either IIS or Tomcat depending on the servername directive.

  • Donna

    This is perfect timing! I posted this question on 2 forums a few weeks ago and didn’t get any real answers. I am a php developer and need to maintain my wamp environment but I also have a need to get up to speed on .net.

    One question though, I want to install Visual Studio Express which according to the Microsoft website requires WebPI to be installed. I assume this bundles in IIS? If not, are there any co-existance issues to be aware of? I assume it’s probably a matter of configuring the port # as you describe above?

    Thanks for this useful article!

    • I’m not sure what WebPI is? Is it the Platform Installer? If so, then it’s a quick and easy way to install and configure IIS modules and software. You can still achieve the same results manually, though.

      Visual Studio Express also comes with a built-in test web server. You don’t strictly need IIS, although I’d recommend it.

      There’s also a third option which Microsoft released recently: IIS Express. I’ll provide more information about that in another post coming soon…

  • Anonymous

    Thanks for the articles, Craig.

    I work with both PHP and ASP.NET projects and end up switching webservers every once in a while. Sometimes hardly at all – sometimes several times a day.

    I made myself a batch file in the end.

    I’m no batch expert, but I looked up a few resources and managed to put together the following:

    @echo off
    sc query “Apache2.2” | find “RUNNING”
    IF %ERRORLEVEL% == 0 (
    GOTO SwitchToIis
    ) ELSE (
    goto SwitchToApache
    net stop “Apache2.2”
    net start “World Wide Web Publishing Service”
    GOTO end
    net stop “World Wide Web Publishing Service”
    net start “Apache2.2”
    GOTO end


    If you save this as a text file and name it “switch-webservers.bat” (or something equivalent and meaningful) then you can add a shortcut to it in your quicklaunch bar in Windows.

    I imagine there’s an AppleScript equivalent, but I’ll leave that to someone who knows what they’re talking about for that ;-)

  • golotyuk

    Thanks for the article!
    One may also try virtual machines for creating .NET or Apache environment (I guess that one of that two is always primarily used)

  • mfr


    What about running both IIS and Apache on a server and having one use a different IP address from the other. That way some sites would point to Apache, while others at IIS.

    Is this possible?

    • That sounds reasonable, although you’d need two IP addresses matched to the same local PC. You’d need to configure your network hardware accordingly, so it’s not a solution which everyone could use.

    • Yes it is possible. I did this years ago, so I can’t remember things 100% but here goes.
      1. Assign at least 2 static ip addresses to your pc. Then you have to configure IIS to listen in on one of those ip addresses, and apache on the other. With IIS, you will have to run a vbs script in the inetpub folder that forces IIS to listen to the ip address. By default IIS binds to all ip addresses, even if you configure it not to in inetmgr. This is true for IIS 5 & 6 but not sure about IIS7.
      2. With Apache, you have to configure it in the httpd.conf file to listen in on the other ip address.
      There might be more steps involved but I can’t remember.
      I used to also have a one web server production environment with only one external static ip address where I had to run both Apache and IIS on the same box.
      This was where it got interesting. I got my firewall to route all port 80 requests to the server, and had Apache acting as the proxy (mod_proxy?). Apache ran on port 80, and the different web sites ran on different ports (91,92 etc).
      Apache would look at the hostnames, then relay them to IIS or serve the pages itself where appropriate.
      But it’s alot of work. Nowaday’s I use IIS & WAMP, and Craig’s services stop/start method.

      • Thanks cmorbutts! Great information and it shows that it’s possible — if a little complicated.

        Let us know if you try it, mfr. For most developers, though, I guess other servers/VMs, alternative ports, or batch files will be the easiest solution.

  • It’s very possible to run .net apps on apache and WAMP.

    Check out mod_aspnet

Get the latest in Front-end, once a week, for free.