Local Virtual Hosts on Windows 7

Hi there!

I’d like to recreate locally an environment similar to our dedicated server.

Therefore I’ve installed on my PC Windows 7:

  • Apache 2.2.21
  • PHP 5.3.8
  • MySQL
  • phpMyAdmin

I am also running IIS on the same PC, so I’ve set Apache on the port 8080.

Everything works fine so far and I did not have any problem.

However I wanted to be able to browse multiple websites locally just typing “mywhateverwebsitename” instead of “localhost:8080”, but it seems I am unable to do it.

I am Administrator on this PC.

I’ve edited the httpd-vhosts.conf file and the Windows hosts file.

In the httpd-vshosts.conf file I have:


NameVirtualHost *:8080

<virtualhost *:8080>
DocumentRoot "C:/DEV/php/"
ServerName phpserver.site
ServerAlias www.phpserver.site
<directory "C:/DEV/php">
AllowOverride All
Options Indexes FollowSymLinks
Order allow,deny
Allow from all
</directory>
</virtualhost>

<VirtualHost *:8080>
	DocumentRoot "C:/DEV/php/"
	ServerName testsite
</VirtualHost>

In the hosts I have just:


127.0.0.1 localhost
127.0.0.1:8080 phpserver.site
127.0.0.1:8080 www.phpserver.site
127.0.0.1:8080 testsite

I did not have any issue with permissions.

If I write in the hosts file the line

127.0.0.1 www.altavista.com

and then try ping www.altavista.com all seems fine and the ping shows the local IP.

If I write in the hosts file the line

127.0.0.1:8080 www.altavista.com

and then try ping www.altavista.com it shows the real public IP of altavista.

If I write

127.0.0.1 phpserver.site

and ping it works and shows the local address (and it shows the IIS home in the browser). If I type

127.0.0.1:8080 phpserver.site

and then try to ping phpserver.site it does not work and the browser shows nothing (not found).

Clearly the hosts file is working properly, and I do not understand where the problem is and if I can do what I want on this PC with this configuration.

I’ve tried to read as much as possible on the topic before posting here, but nothing seems to work, therefore I’m assuming there is something I don’t know or did not understand!

I would really appreciate some help!!

Many thanks!!! :slight_smile:

You can’t put ports in the hosts file, only IP address -> domain name mappings

If you have the 127.0.0.1 phpserver.site in your hosts file, you should be able to visit phpserver.site:8080 and see the site Apache is serving.

Hi ScallioXTX, many thanks for your reply…

That’s one thing I did not know, although I was guessing it eheh

So let’s say I have

127.0.0.1 mytest.site

in my Windows hosts file.

Then I have

<VirtualHost *:8080>
	DocumentRoot "C:/DEV/php/"
	ServerName mytest.site
</VirtualHost>

in my httpd-vhosts.conf file.

When I type mytest.site in my browser it goes to IIS and not Apache :frowning:

What am I doing wrong? (I’m sure many things eheheh :smiley: )

Edit: Nevermind, I did not read the address you wrote properly sorry! So I can’t just have mytest.site, I need anyway to use the :8080 at the end?

Hi again!

Using the port with the name it works perfectly, so many thanks!! :slight_smile:

Is there a way to reach these subdomains I create on my PC locally from another PC (browser) on the same LAN?

Browsers will connect to port 80 by default, so if you your server running on a different port you need to supply it; there is no way around that.

As for the other PC in the LAN, yes, that can also access your if you put the same domain name and your LAN IP in their host file.

For this to work you need either Listen 8080, Listen *:8080 or Listen <your LAN IP>:8080 in the httpd.conf. Listen 127.0.0.1:8080 will not work.
(my personal preference is just the port, so Listen 8080, but it’s up to you :))

Many many thanks!!

What you wrote, it is very clear to me if I want my colleague to reach the localhost:8080, myIP:8080.

Providing that there is nothing preventing the connection (like a firewall setting, etc.) I would expect this to work fine.

Now, in case I do not want the user to connect to one of the subdomains I created through both the hosts and httpd-vhost.conf files.

How would my colleague reach it?

I was wondering tif this should go through a different, additional port?

Any suggestion?

Many thanks!! :slight_smile:

I’m not entirely sure I get that last question, but it sounds like you’re looking for Access control :slight_smile:

Oops sorry, I inserted a “not” too much in my post eheh

This is the scenario.

Apache root localhost:8080 on my PC.
If my colleague types myIP:8080 it should show the above.

On my PC I have a subsite namesomething (127.0.0.1 namesomething in hosts and the related code in httpd-vshost.conf).
Therefore on my PC I can type namesomething:8080 in my address bar and see this local website.

Now I would like my colleague being able to browse this subwebsite from his PC, using a standard browser.

Any idea?! :slight_smile:

You can do if you add the name of that site to your colleague’s host file.
There are other ways, but this is by far the simplest :slight_smile:

Good responses, Rémon. As noted, if you have a conflict between servers on the same system, one is allowed port 80, the other is usually relegated to 8080.

My first question is WHY keep IIS if you have a good server to use, i.e., Apache? Isn’t it more trouble than it’s worth to use the 8080 port work around?

As for your LAN cohorts, if they update their hosts file (on Win7, that’s C:\Windows\system32\drivers\etc\hosts) with your LAN address (is it fixed or dynamic - that will be a problem if the latter) and the 8080 port but I’d make sure that any “domains” that you want to protect are not under localhost! I keep all my test domains on the W: (for web) partition and use acronyms for each for my own benefit but that could provide some security (by obfuscation) within your LAN. If that’s not sufficient, password protect your domains (with a site login if you can’t use file attributes or Apache’s password protection)!

Regards,

DK

Hi and thanks to both for your replies! :slight_smile:

You are right in normal conditions I would do differently, but firstly I have to develop also using .NET and Classic ASP, so Apache is not the right environment. This hopefully will be a temporary situation, but it could be “temporary” for a while eheh

Anyway, I should just write
myIP namesomething
in the hosts file of my colleague?

Too good to be true :smiley: but I’ll give it a go!!! :slight_smile:

Many thanks again, I’ll come back here crying if (when) I’ll fail my attempt eheheh :slight_smile:

You could, if you want, run the Apache website through a reverse proxy from IIS, or the other way around.
That way you just have one port, makes it a lot easier :slight_smile:
It would cost more data traffic, but since it’s all on the same host it doesn’t really matter.

Hello again!!!

Just popped up to say thank you again.

Everything is working absolutely fine and I have to say it was very easy in the end.

That is how I proceeded:

  1. Allowed a range of local IPs on my Domain network in Windows 7 Firewall by creating a Connection Security Rule (this itself obviously allowed my colleagues to browse the IIS websites easily);
  2. The hosts file on my colleague’s Windows 7 PC, same LAN, was edited just adding the line myIP nameofmylocalapacheSubsite (for example 192.168.1.33 mylocal.website).

And that was it! :slight_smile:

All fine, all happy :slight_smile:

Thank you again very much!! (: