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

Share this article

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: start-apache.bat 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
stop-apache.bat This will stop Apache (change the service name if necessary).

@net stop Apache
start-iis.bat This will stop Apache and start/restart IIS.

@call stop-apache.bat
@call stop-iis.bat
@net start W3SVC
stop-iis.bat This will stop IIS on Windows Vista or 7.

@net stop was /y
stop-iis.bat 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?

Frequently Asked Questions (FAQs) about Running Apache and IIS on the Same PC

Can Apache and IIS run simultaneously on the same machine?

Yes, Apache and IIS can run simultaneously on the same machine. However, they cannot listen to the same port at the same time. By default, both Apache and IIS listen to port 80. To avoid conflict, you need to change the listening port of one of the servers. This can be done by editing the configuration file of the respective server.

How can I change the listening port of Apache or IIS?

To change the listening port of Apache, you need to edit the httpd.conf file. Locate the line that says “Listen 80” and change it to “Listen [new port number]”. For IIS, open the Internet Information Services (IIS) Manager, select the website you want to change, click on “Bindings” in the right panel, and then change the port number.

Can I access both servers from the same browser?

Yes, you can access both servers from the same browser. To access the server running on the default port (80), you just need to enter the URL. To access the server running on a different port, you need to specify the port number in the URL, like this: http://localhost:[port number].

What are the advantages of running both Apache and IIS on the same machine?

Running both Apache and IIS on the same machine allows you to take advantage of the unique features of both servers. For example, IIS is known for its tight integration with Windows and its user-friendly interface, while Apache is known for its flexibility and robustness.

Are there any security concerns when running both servers on the same machine?

Running multiple servers on the same machine can increase the attack surface. Therefore, it’s important to keep both servers updated with the latest security patches. Also, make sure to configure the servers properly to minimize potential security risks.

Can I run other services along with Apache and IIS on the same machine?

Yes, you can run other services along with Apache and IIS on the same machine. However, you need to ensure that these services do not conflict with each other, especially in terms of port usage.

How can I troubleshoot issues when running both servers on the same machine?

Both Apache and IIS provide logging features that can help you troubleshoot issues. Check the error logs of the respective server for any error messages. Also, use tools like netstat to check if the servers are listening on the correct ports.

Can I run both servers as services?

Yes, both Apache and IIS can be run as services. This means that they will start automatically when the machine boots up.

How can I switch between the two servers?

To switch between the two servers, you need to stop the currently running server and start the other one. This can be done using the respective control panels of the servers.

Can I use a reverse proxy to run both servers on the same port?

Yes, you can use a reverse proxy to run both servers on the same port. The reverse proxy will listen on port 80 and forward requests to the appropriate server based on the request URL or other criteria.

Craig BucklerCraig Buckler
View Author

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.

apacheiiswindows
Share this article
Read Next
Get the freshest news and resources for developers, designers and digital creators in your inbox each week