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

    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?