Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,628
    Thanks
    6
    Thanked 1,002 Times in 975 Posts

    2 computers – how to resolve “localhost” to “10.0.2.2”?

    OK, I have two computers that are connected via LAN (wireless), let’s call them computer A and computer B. Computer B is running Apache (XAMPP) and I can access computer B from computer A at http://10.0.2.2. When I install software (e. g. a CMS) that works with “localhost” I can’t type http://localhost/whatever on computer A to access the files on computer B because it thinks it has to look for its own local host. So far so clear.

    However, if I type http://10.0.2.2/whatever it still resolves to “localhost” and therefore doesn’t work because computer A thinks it has to look in its own server. If I change “localhost” to “10.0.2.2” in the config file of the program on the server I can access the files on the server on both machines via “10.0.2.2” (or “localhost” on computer B) – but only if computer A is on at the same time (probably due to a detour via computer A?).

    The question now is: How do I always resolve “localhost” on computer B to “10.0.2.2” on computer A (so I can use “localhost” in the program config and don’t have to change it manually whenever computer A isn’t on)?

    We’re talking about Macintosh, by the way.

  • #2
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    Changing localhost to be something other than the actual local computer isn't a good idea. Other programs and services might be relying on localhost actually being the local computer.

    If the CMS is installed on the web server, what does computer A have to do with it? If the CMS is configured to look for it's files/database on localhost, why would where the page is being accessed from matter? I guess I am failing to see what the actual problem is.
    OracleGuy

  • #3
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,628
    Thanks
    6
    Thanked 1,002 Times in 975 Posts
    Sorry, maybe I descibed it more complicated than necessary.

    Hm, I think it’s not even related to the server itself but more a root domain/base URL issue. Computer B has the CMS where in the config file “localhost” is specified as server root/base URL. This always changes the URL to http://localhost/ on computer A, even if I write http://10.0.2.2/ which results in a connection related error message on computer A.

    If I change the root URL to http://10.0.2.2/ in the config file I can access files on computer B’s server from computer A, and I can also view the files on the server on computer B through that address (and “localhost” is resolved/redirected to “10.0.2.2”), but only if computer A is connected. If computer B (which holds the sever) is the only one that’s running then 10.0.2.2 won’t work for some reason.

    How can I make it that 10.0.2.2 always works on computer B even if computer A is off?

    Sorry, this is a little hard to explain.

  • #4
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,852
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    However, if I type http://10.0.2.2/whatever it still resolves to “localhost” and therefore doesn’t work because computer A thinks it has to look in its own server. If I change “localhost” to “10.0.2.2” in the config file of the program on the server I can access the files on the server on both machines via “10.0.2.2” (or “localhost” on computer B) – but only if computer A is on at the same time (probably due to a detour via computer A?).
    You may make a virtual server(leaving your loacalhost intact for your actual server) and specify a different name, say mysite.com. So, from the other computer, you may access the same virtual server by specifying the IP of your computer A in the hosts file.

    I'll be posting the steps after sometime....
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #5
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,852
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    In my xampp, to make a virtual server named local.domain.com I'd follow the steps below... (Using simple editors like notepad/++, otherwise they may get corrupted)

    In computer A
    1. Create a folder under the C:\xampp\htdocs\, named domain
    2. Open the file C:\xampp\apache\conf\extra\httpd-vhosts.conf and add
      Code:
      <VirtualHost *:80>
          DocumentRoot "C:\xampp\htdocs\domain"
          ServerName local.domain.com
          #I canadd some other rules, if I wish
       </VirtualHost>
    3. Open C:\WINDOWS\system32\drivers\etc\hosts and add
      Code:
      127.0.0.1 local.domain.com
    4. Restart apache and network service and try the newly created domain name in a browser in computer A

    In computer B
    1. Open C:\WINDOWS\system32\drivers\etc\hosts and add
      Code:
      10.0.2.2 local.domain.com
    2. Restart network services and try the domain in computer B


    In this way, I don't have to interfere with the reserved domain name localhost in any of my computers and I get the same /root/folder structure just like in my actual server.
    Hope this is what you required.
    Last edited by abduraooft; 10-27-2009 at 12:14 PM.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #6
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,628
    Thanks
    6
    Thanked 1,002 Times in 975 Posts
    Hmm… actually I’m really stupid. Looking to find out how to add a host entry in Mac OS I came across the name “Bonjour” which is Apple’s zero-config network standard. I never cared about what this actually is and does but then I read that the computers identify themselves through their Bonjour names. So all I have to use is “computername.local” as base URL rather than the computer’s IP and I never run into any problems.

    Pfff… so simple that it’s embarassing.


  •  

    Tags for this Thread

    Posting Permissions

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