Switching between Running Apache and IIS in Windows

When one installs Apache in Windows Machine where IIS is installed, starting Apache will give the following error :

The Apache service named  reported the following error:
>>> (OS 10013) An attempt was made to access a socket in a way forbidden by its access permissions.
:make_sock: could not bind to address 0.0.0.0:80.

The reason is both the servers listen on Port 80. Even though you can make one of the servers to listen in different port it is too many changes to make things work.

Easier way is to have these servers running alternatively using simple batch scripts.

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, create 4 batch (.bat) files in the same folder.

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.

Source : sitepoint.com

Advertisements