Page 1 of 1

Different IP address for 'localhost' and MySQL

Posted: Thu Mar 05, 2009 12:29 pm
by dambis
OK, so I run MySQL on remote server.

So far we have tons of users they have a difficulties to understand that they need to use another IP address instead of 'localhost' in MySQL configuration for their scripts.

So I decided to find a solution so they can continue using localhost as MySQL hostname but PHP would understand that localhost is actually different IP address.

SO I edited /etc/hosts and set something like:

10.0.0.3 localhost
#127.0.0.1 localhost

Where 10.0.0.3 MySQL server IP.

Now When I do ping localhost I see that my localhost has 10.0.0.3 address. Very nice!

Unfortunately when I try to connect to this fake 'localhost' from PHP script, it gets ignored and it still tries to access local MySQL server (which is not installed at all).

I have restarted Apache after made changes to /etc/hosts. Moreover as I said 'ping localhost' gives 10.0.0.3 Ip , so Its OK.

But not for Apache/PHP. It is somehow possible to let Apache/PHP think that 'localhost' has value which is set on /etc/hosts ?

Re: Different IP address for 'localhost' and MySQL

Posted: Thu Mar 05, 2009 3:32 pm
by VladSun
I think this is a very wrong approach to solve this "problem". Other software may rely on proper "localhost" resolving (i.e. 127.0.0.1)

Anyway: try to add

Code: Select all

order hosts, bind
in your /etc/host.conf file