I’ve been developing PHP websites against mysql on Windows Server 2003 and Windows Server 2008 R2 and finally decided I needed to start doing my testing and debugging on a client machine instead.  My development machine runs Windows 7 so it is running the same version of IIS as my Windows Server 2008 R2 machine.

As I was getting everything setup, I installed phpMyAdmin and immediately ran into a problem.  It would time out trying to connect to the database on localhost.  Of course, I didn’t know that at the time as phpMyAdmin just displays a blank page.  I found this article by Karina Myers that described a workaround – specify 127.0.0.1 for the host instead of local host.  Specifically, change this:

$cfg[‘Servers’][$i][‘host’]    = ‘localhost’;

to this:

$cfg[‘Servers’][$i][‘host’]    = ‘127.0.0.1’;

Then I proceeded to install an osCommerce website and it had trouble as well.  Fortunately I had Xdebug installed so I got some useful error messages.  I should have guessed this before; the problem had to do with the mysql_connect() function trying to connect to localhost.

Fortunately for me, others have run into this before and the solution was posted to the documentation page for mysql_connect.  Here is what you do:

  1. Edit the %SystemDrive%\System32\drivers\etc\hosts file.
  2. Make sure the following line is not present or is commented out:
    ::1         localhost
  3. Make sure the following line is present and is not commented out:
    127.0.0.1   localhost

Doing this solved the problem completely for me.

Update 12/29/2009

I discovered tonight that this tip also fixes a problem I was having with the Beyond TV web admin on Windows Vista. When attempting to connect from the local machine by right-clicking on the Beyond TV tray icon and selecting Open Web Admin the browser would display an error page. After making the above changes to the hosts file, all was right with the world again.

Resources