Weird behavior with apache/mysql
Hello,
I want to do a php page the connects to a mysql database and do a query. $link = mysql_connect('127.0.0.1', 'root', 'password'); if (!$link) { die('Error, cannot connect : ' . mysql_error()); } echo 'Connection succeed'; mysql_close($link); It doesn't work BUT It works when I replace 127.0.0.1 by localhost. Although I have in /etc/hosts 127.0.0.1 localhost.localdomain localhost It doesn't work with remote machines even if I added them in /etc/hosts 10.0.0.2 remotemachine It looks like a dns reverse resolution issue but I'd like to fix the Apache conf more than update the dns. apache version = 2.0 php version = 5 If any idea let me know, thanx |
First of all, resolving "localhost" is normally done via your /etc/hosts file, not via DNS.
That is, if the file /etc/host.conf specifies "hosts,bind", in that order, as name resolver methods (basically this tells the name resolver to first check out /etc/hosts and if that fails, use DNS instead). Reverse DNS is normally not an issue either, if /etc/host.conf is set up correctly. By the way, "localhost" should only be known on your machine (eg in /etc/hosts), never defined in DNS. Secondly, remote machines can't access your machine via it's "localhost" interface. Each machine has it's own "localhost". For communication between 2 machines, you always need their fully qualified hostname or IP address. Note that there may be some firewall issues too (firewalls may be blocking your HTTP port - eg port 80). To test this, try browsing to your fully qualified hostname: http://your_host.your_domain (this uses port 80 by default, which should be OK). Could you please verify the port and IP address to which your webserver listens? This is in your /etc/httpd.conf. |
All times are GMT -5. The time now is 12:06 AM. |