10.1: localhost goes away... and other VirtualHost issues

slur

Geek / Hedonist
I noticed after updating to 10.1 that the "virtual hosts" I set up with NetInfo Manager and through httpd.conf are suddenly being overridden in a weird way.

I was using a few of these virtual hosts to specify subdirectories where I had different tools I had written in PHP and MySQL. For example, the ~/username/Sites/ directory was myhostname.com, the ~/username/Sites/SQL/ directory was set to sql.myhostname.com, etc.

But after updating to 10.1 the permissions I had set up in the 'mysql' database weren't any good any more because my hostname was suddenly resolving to 'localhost.pop.ptld.qwest.net' - a hostname that was clearly being supplied by my DSL router. So if I tried to connect to MySQL from my PHP script the error would come back that I didn't have permission to connect from that domain!

Likewise when my iBook is unconnected to any network I'll log into the terminal and the hostname shown in the terminal prompt will be 'localhost.' But when I hook it up to the network at the office it becomes 'dhcp1142.' Clearly something has changed in the way that NetInfo is managing my hosts / domains.... I'm guessing that it's using the DNS / DHCP server to set the domain / host names. How can I set up NetInfo so that it behaves as it did in 10.0.x?
 

wsanchez

Registered
localhost is the name of the loopback address (127.0.0.1). It's a network address to your computer which does not actually go over the wire.

When you have IP over a network interface enabled, you get another address, and that address may also have a name, usually resolvable via DNS. 10.1 sets your system hostname to the first such name is finds.

This has no effect on the name "localhost" which still refers to the loopback address.

If you want to set your hostname to a fixed name, you can edit /etc/hostconfig and replace -AUTOMATIC- in the hostname entry with the name you want. This only changes the system's notion of it's own name, and not the name of your network addresses, though, which is why I have a hard time understanding how this related to whether you can connect to your local web server with the localhost name.

My guess is that something else is wrong with your Apache config and that it issue is a red herring.
 

pbzin

Registered
I've discovered if I use the numeric ip address, rather than "localhost" it works. I haven't tried messing with some of the things suggested in the previous post. I'll give those a shot. Thanks.
 

wsanchez

Registered
OK, if 127.0.0.1 works and localhost doesn't something is broken...

In Terminal, try "ping localhost" and see if you get any responses back. Should look like:

[bartleby:~] wsanchez% ping localhost
PING localhost.knownow.com (127.0.0.1): 56 data bytes
64 bytes from 127.0.0.1: icmp_seq=0 ttl=255 time=0.316 ms
64 bytes from 127.0.0.1: icmp_seq=1 ttl=255 time=0.281 ms
...

If that's not working, your computer doesn't have an entry for localhost, which is the problem. Try "nidump hosts ." and see if a line for localhost shows up. It should at least print an entry for localhost and broadcasthost. Probably that'll be it:

[bartleby:~] wsanchez% nidump hosts .
127.0.0.1 localhost
255.255.255.255 broadcasthost

If or or both is missing, your NetInfo config is wonky, and that's your problem. How that happened, I have no clue.
 

pbzin

Registered
Thanks wsanchez,

Ping workes as you described. Nimdump did not return either localhost or broadcasthost. How do I fix this?
 

wsanchez

Registered
sudo nicl .
cd /machines
mk localhost
cd localhost
mk . ip_address 127.0.0.1
cd ..
mk broadcasthost
cd broadcasthost
mk . ip_address 255.255.255.255
 

Zim

Registered
I found I also had to edit rc.boot and change localhost to my desired host name there (I have a dyndns acct).

I don't recall having to do that under 10.0.x

Mike
 

Klink

Member
Hello wsanchez, Fred,

I'm very pleased to see your reawakened involvement in discussions here at macosx. Where do you find the time, with Knownow and such?

Just would like to express appreciation for the wonderful paper written on "The Challenges of Integrating the Unix and Mac OS Environments". I found it eye opening and inspirational, a must read for members frequenting unix related discussions.


http://www.mit.edu/people/wsanchez/papers/USENIX_2000/
 

pbzin

Registered
Hmm...

When I "cd/ machines" I get a directory not found message. Where exactly is "machines"?

BTW, in netinfo manager there is a "machines" directory which contains "localhost" and a "broadcast". Does this make any difference?

Thanks...
 

slur

Geek / Hedonist
What you're seeing in wsanchez's post are commands being sent through nicl - the NetInfo command-line utility. When you type 'nicl .' you're taken into the command-mode for NetInfo, and /machines is a NetInfo directory, not a disk directory.

By the way, to exit nicl press control-D.

To learn more enter man nicl in the terminal.
 

pbzin

Registered
Thank's for the clarification, slur.

I made the changes wsanchez suggested, but it made no difference. I can only log onto "http://localhost/" if I have an active internet connection - Airport, ethernet, etc. If I disconnect, I must use the numeric ip - 127.0.0.1. Interestingly, all my php/perl scripts run correctly even though they are configured to look for "localhost". Since everything is working, I don't mind having to type in the numeric ip. I'm just a little baffled by why it works this way.
 

slur

Geek / Hedonist
I finally set up my machine with named virtual hosts so that I can use different "domain names" for my development websites. It works like a charm in the browser and elsewhere. But for some reason I'm still getting stupid complaints from MySQL when I try to connect using 'localhost' or 'sql.albinomac.com' or anything else that's supposed to resolve to 127.0.0.1.

Warning: Host 'localhost.mn.uswest.net' is not allowed to connect to this MySQL server in /Users/slurslee/Sites/CVS/sqlwebtool/common/mysql_tools.php on line 148
Warning: MySQL Connection Failed: Host 'localhost.mn.uswest.net' is not allowed to connect to this MySQL server in /Users/slurslee/Sites/CVS/sqlwebtool/common/mysql_tools.php on line 148


And I'm not doing anything unusual, I swear:
mysql_connect('localhost', 'my_username', 'my_password');

It's obvious what's going on. It appears that for some reason PHP or Apache, or someone in the chain is looking up 127.0.0.1 and obtaining the hostname in another manner. If I execute nslookup from the terminal I get a similar result:

nslookup localhost
Server: ptldpop1.ptld.uswest.net
Address: 198.36.160.1

Non-authoritative answer:
Name: localhost
Address: 127.0.0.1

nslookup localhost.mn.uswest.net
Server: ptldpop1.ptld.uswest.net
Address: 198.36.160.1

Name: localhost.mn.uswest.net
Address: 127.0.0.1


Is there some way to get Apache/PHP/MySQL to take me at my word? When I say 'localhost' I mean 'localhost' goldarn it!
 

brianwells

Registered
I had the same problem, but discovered that http://localhost works just fine in: Netscape 6.1; Opera 5.0 b1.327; OmniWeb 4.0.5. Only Internet Explorer 5.1.2 (3707) - which apparently was installed with Mac OS X 10.1 - complains that it can't find the server.

Originally posted by pbzin
I have the same problem. I work offline to do php/mysql stuff and now can't point my browser to "localhost", or any variation "http:///", http://localhost/, etc.

What gives??
 
Top