Running Apache and MySQL side-by-side with IIS (or WebMatrix and Web Platform)

As a rule, only 1 process is allowed to bind to a specific IP:port (an interface). And the first process that takes that specific IP:port will prevent all other processes, that use the same IP:port, from starting…

Apache and IIS will both try to take port 80 (the HTTP port) and port 443 (the HTTPS port) – on IP “0.0.0.0”.

MySQL will try to take port 3306 (the default MySQL port) – on either IP “0.0.0.0” or IP “127.0.0.1”.

“0.0.0.0” specifies binding to all IP addresses the system has, including 127.0.0.1. And “127.0.0.1” is the standard localhost IP – used to bind services for local-access only.

To run multiple servers side-by-side (on the same system), 3 options are available (from the very simple to the more complicated):

A) Run Only 1 Platform at a Time

Stop IIS, start Apache. And vice-versa.

With multiple MySQL instances, run 1 instance at a time.

Note that when using both MySQL and SQL Server, you can run both at the same time as they use different ports (and they will not conflict).

B) Keep Listeners Bound to the Default IP(s), But On Different Ports

This is only a valid solution for local use and local development.

Select each website in IIS (including the Default Website), change the binding properties from *:80 and *:443 to other ports such as 8080 and 8443.

Update Web Platform’s MySQL’s my.ini file to change “port = 3306″ to another port such as 3307.

Update URLs to Use New Ports

With the above re-binding, all IIS websites will now be reachable from URL:

http://domain.name:port/

How URLs Work

By convention, all web-servers use the same standard ports (for HTTP and HTTPS)…

When a request is made from your Browser to http://domain.name/path/, it resolves the domain name to an IP address, and the request is automatically sent to that IP on port 80 (and to port 443 for HTTPS traffic).

In effect, all standard URLs (i.e., without a user specified port) are short-hand for:

http://domain.name:80/
https://domain.name:443/

Update Database Connections

Webapp configuration files, other script files, and any programs that connect to Web Platform’s MySQL, will need to be updated to reflect the new port number to use.

This includes phpMyAdmin (phpmyadmin\config.inc.php).

C) Keep Default Ports, But Bind Listeners On Separate IP Addresses

Your system will likely have:

  • 1 Public IP
  • 1 LAN IP (such as 192.168.0.1 – which is accessible from all LAN connected systems and devices)
  • 1 localhost/loopback IP 127.0.0.1 (only locally reachable)
  • Many IPs in the range of 127.0.0.xx (that are only locally reachable)

It is best to have WampDeveloper’s Services include the use of IP 127.0.0.1 – otherwise you’ll have to use an editor to do an auto-search for all instances of 127.0.0.1 (and some variations that can be picked up with string “127”) in WampDeveloper’s folder to update the local configuration structure for use of another local IP.

Bind Apache from the default of “0.0.0.0” to specific IPs (including IP 127.0.0.1). And Web Platform’s IIS to another specific IP. And perform the same for multiple MySQL servers…

For Apache

Edit file – C:\WampDeveloper\Config\Apache\httpd.conf
Replace these two lines (one is at the beginning, the other at the end) –

Listen 80
...
Listen 443

With –

Listen ip.address.here:80
...
Listen ip.address.here:443

Preferably also include Listen 127.0.0.1:80 and Listen 127.0.0.1:443.

For Web Platform

Select all websites (including Default Website) in IIS and change their bindings to the other IP.

If another instance of MySQL was installed (via Web Platform), edit its “C:\Program Files\MySQL\MySQL Server\my.ini” file and change bind-address = 127.0.0.1 to the other IP.

If you have to keep Web Platform’s MySQL server on 127.0.0.1, bind WampDeveloper’s MySQL to something other than 127.0.0.1:

Edit file – C:\WampDeveloper\Config\Mysql\my.ini
Update line bind-address = 127.0.0.1.

Edit file – C:\WampDeveloper\Tools\phpMyAdmin\config.inc.php
Update all instances of “127.0.0.1” (that is used for the connection IP and in the access control list).

ProxyPass

You can run multiple servers at the same time and use the ProxyPass feature to have Apache act as the front-end, transparently proxying requests back-and-forth for specific URLs and websites.

This way you can have 1 public-facing server (Apache on port 80) serving all requests, and multiple back-end servers such as IIS and Tomcat running websites and scripts that use ASP.NET and Java.

One thought on “Running Apache and MySQL side-by-side with IIS (or WebMatrix and Web Platform)”

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>