Visit Jeremy's Blog.
Go Back > Forums > Linux Forums > Linux - General
User Name
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.


  Search this Thread
Old 01-04-2006, 04:11 AM   #1
Registered: Dec 2002
Location: London / Paris
Distribution: Debian / OpenBsd
Posts: 74

Rep: Reputation: 15
Weird behavior with apache/mysql


I want to do a php page the connects to a mysql database and do a query.

$link = mysql_connect('', 'root', 'password');
if (!$link) {
die('Error, cannot connect : ' . mysql_error());
echo 'Connection succeed';

It doesn't work BUT
It works when I replace by localhost. Although I have in /etc/hosts localhost.localdomain localhost
It doesn't work with remote machines even if I added them in /etc/hosts 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
Old 01-04-2006, 05:37 AM   #2
Senior Member
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515

Rep: Reputation: 61
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:
(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.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Weird behavior Bassy Linux - Software 2 10-20-2005 02:32 PM
weird mount behavior sohmc Linux - Hardware 0 06-07-2005 08:06 AM
iptables ... weird behavior, please help! matrixcubed Linux - Networking 0 05-09-2005 10:44 AM
weird behavior in firefox sether *BSD 5 09-06-2004 05:05 PM
Weird Knode behavior PapaNoHair Mandriva 0 11-09-2003 07:39 PM > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 12:49 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration