Go Back   CodingForums.com > :: Server side development > Apache configuration

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-26-2009, 05:32 PM   PM User | #1
VIPStephan
The fat guy next door


 
VIPStephan's Avatar
 
Join Date: Jan 2006
Location: Halle (Saale), Germany
Posts: 7,703
Thanks: 5
Thanked 875 Times in 850 Posts
VIPStephan is a jewel in the roughVIPStephan is a jewel in the roughVIPStephan is a jewel in the rough
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.
__________________
Don’t click this link!
VIPStephan is offline   Reply With Quote
Old 10-26-2009, 06:05 PM   PM User | #2
oracleguy
Rockstar Coder


 
Join Date: Jun 2002
Location: USA
Posts: 9,042
Thanks: 1
Thanked 322 Times in 318 Posts
oracleguy is a jewel in the roughoracleguy is a jewel in the roughoracleguy is a jewel in the rough
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
oracleguy is offline   Reply With Quote
Old 10-26-2009, 10:21 PM   PM User | #3
VIPStephan
The fat guy next door


 
VIPStephan's Avatar
 
Join Date: Jan 2006
Location: Halle (Saale), Germany
Posts: 7,703
Thanks: 5
Thanked 875 Times in 850 Posts
VIPStephan is a jewel in the roughVIPStephan is a jewel in the roughVIPStephan is a jewel in the rough
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.
__________________
Don’t click this link!
VIPStephan is offline   Reply With Quote
Old 10-27-2009, 10:51 AM   PM User | #4
abduraooft
Supreme Master coder!

 
abduraooft's Avatar
 
Join Date: Mar 2007
Location: N/A
Posts: 14,689
Thanks: 158
Thanked 2,184 Times in 2,171 Posts
abduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really nice
Quote:
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....
__________________
Quote:
The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)
abduraooft is offline   Reply With Quote
Old 10-27-2009, 12:10 PM   PM User | #5
abduraooft
Supreme Master coder!

 
abduraooft's Avatar
 
Join Date: Mar 2007
Location: N/A
Posts: 14,689
Thanks: 158
Thanked 2,184 Times in 2,171 Posts
abduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really nice
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.
__________________
Quote:
The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

Last edited by abduraooft; 10-27-2009 at 12:14 PM..
abduraooft is offline   Reply With Quote
Old 10-28-2009, 04:25 PM   PM User | #6
VIPStephan
The fat guy next door


 
VIPStephan's Avatar
 
Join Date: Jan 2006
Location: Halle (Saale), Germany
Posts: 7,703
Thanks: 5
Thanked 875 Times in 850 Posts
VIPStephan is a jewel in the roughVIPStephan is a jewel in the roughVIPStephan is a jewel in the rough
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.
__________________
Don’t click this link!
VIPStephan is offline   Reply With Quote
Reply

Bookmarks

Tags
apache, lan, localhost, network, resolve

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:53 AM.


Advertisement
Log in to turn off these ads.