Different IP address for 'localhost' and MySQL
Posted: Thu Mar 05, 2009 12:29 pm
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 ?
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 ?