SitePoint Sponsor

User Tag List

Results 1 to 13 of 13
  1. #1
    SitePoint Member
    Join Date
    Dec 2011
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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:

    Code:
    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:

    Code:
    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
    Code:
    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
    Code:
    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
    Code:
    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
    Code:
    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!!!

  2. #2
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    8,907
    Mentioned
    139 Post(s)
    Tagged
    2 Thread(s)
    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.
    Rémon - Hosting Advisor

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  3. #3
    SitePoint Member
    Join Date
    Dec 2011
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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
    Code:
    127.0.0.1 mytest.site
    in my Windows hosts file.

    Then I have
    Code:
    <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

    What am I doing wrong? (I'm sure many things eheheh )

    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?

  4. #4
    SitePoint Member
    Join Date
    Dec 2011
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi again!

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

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


    Quote Originally Posted by ScallioXTX View Post
    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.

  5. #5
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    8,907
    Mentioned
    139 Post(s)
    Tagged
    2 Thread(s)
    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 )
    Rémon - Hosting Advisor

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  6. #6
    SitePoint Member
    Join Date
    Dec 2011
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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!!


    Quote Originally Posted by ScallioXTX View Post
    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 )

  7. #7
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    8,907
    Mentioned
    139 Post(s)
    Tagged
    2 Thread(s)
    I'm not entirely sure I get that last question, but it sounds like you're looking for Access control
    Rémon - Hosting Advisor

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  8. #8
    SitePoint Member
    Join Date
    Dec 2011
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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?!

  9. #9
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    8,907
    Mentioned
    139 Post(s)
    Tagged
    2 Thread(s)
    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
    Rémon - Hosting Advisor

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  10. #10
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,607
    Mentioned
    19 Post(s)
    Tagged
    2 Thread(s)
    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
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  11. #11
    SitePoint Member
    Join Date
    Dec 2011
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi and thanks to both for your replies!

    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 but I'll give it a go!!!

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




    Quote Originally Posted by dklynn View Post
    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

  12. #12
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    8,907
    Mentioned
    139 Post(s)
    Tagged
    2 Thread(s)
    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
    It would cost more data traffic, but since it's all on the same host it doesn't really matter.
    Rémon - Hosting Advisor

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  13. #13
    SitePoint Member
    Join Date
    Dec 2011
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs up

    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!

    All fine, all happy

    Thank you again very much!!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •