After installed Apache, MySQL, PHP on Windows 2008 R2 64-bit, I ‘m facing the strangest problem ever.

My OS is 64-bit, but Apache, MySQL, PHP are all of 32-bit version. Though MySQL has official 64-bit version released, but I don’t see any benefit while Apache and PHP have not.

When phpMyAdmin is installed and setup, I use Firefox to access it, it took a long time but no response. I read phpMyAdmin‘s document and it says:

When using the “cookie” authentication method, the mcrypt extension is strongly suggested for most users and is required for 64–bit machines. Not using mcrypt will cause phpMyAdmin to load pages significantly slower.

But I checked and checked and sure that I’ve installed mcrypt support successfully.

After all, I wrote a very simple test program contains only one line:

1
$link = mysql_connect('localhost', 'root', '') or die('Could not connect: ' . mysql_error());

The same thing happened again… and the error message says:

Warning: mysql_connect() [function.mysql-connect]: [2002] A connection attempt failed because the connected party did not (trying to connect via tcp://localhost:3306) in E:\HTTPD\htdocs\test.php on line 2

Warning: mysql_connect() [function.mysql-connect]: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. in E:\HTTPD\htdocs\test.php on line 2

Fatal error: Maximum execution time of 30 seconds exceeded in E:\HTTPD\htdocs\test.php on line 2

But wait…

Here the problem is quite clear: PHP can’t find localhost server.

And the reason is so simple that Windows 2008 R2 resolve localhost to ::1: in IPv6 format by default not 127.0.0.1 in IPv4 format, and PHP is not IPv6 safe. So, connection is always timeout.

Knowing the reason, there is no need for solution any more.