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.
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:
On IIS, you change the Bindings setting in the IIS Manager:
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…
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:
(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.
Learn PHP for free!
Make the leap into server-side programming with a comprehensive cover of PHP & MySQL.
RRP $11.95 Yours absolutely free
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?
Craig is a freelance UK web consultant who built his first page for IE2.0 in 1995. Since that time he's been advocating standards, accessibility, and best-practice HTML5 techniques. He's created enterprise specifications, websites and online applications for companies and organisations including the UK Parliament, the European Parliament, the Department of Energy & Climate Change, Microsoft, and more. He's written more than 1,000 articles for SitePoint and you can find him @craigbuckler.
Jump Start Git, 2nd Edition
Visual Studio Code: End-to-End Editing and Debugging Tools for Web Developers