I'm running local sandbox on OS X 10.6. Been doing so for quite sometime. Ran an software update and now everything seems to be jacked up. Here's the basic problem: I'm unable to connect to MySQL using PHP when defining the host as "localhost", which I need in order to keep in sync with the rest of the team. First, the relavant code. Here's my test php script:
<?php$usr = "root";$pass = "";$host = $_SERVER['HTTP_HOST'];//connection to the database$dbhandle = mysql_connect($host, $usr, $pass) or die("Unable to connect to MySQL"); echo "Connected to MySQL";?>
And here's my httpd-vhosts.conf file: NameVirtualHost *:80<VirtualHost *:80> ServerName localhost DocumentRoot /Users/admin/Development</VirtualHost><VirtualHost *:80> ServerName local DocumentRoot /Users/admin/Development</VirtualHost><VirtualHost *:80> ServerName test DocumentRoot /Users/admin/Development</VirtualHost>
So, with this config, navigating to "127.0.0.1", "local" or "test" into my browser, I'm able to connect to MySQL. The test script returns: "Connected to MySQL". But, if I enter in "localhost" the script dies giving me the output: "Unable to connect to MySQL". If I set the hostname to 127.0.0.1 or any VirtualHost ServerName as defined in my httpd-vhosts.conf file, excluding 'localhost', it works. That is to say, in my example PHP script I'm using $_SERVER['HTTP_HOST'] but can also statically set $host to '127.0.0.1', 'local' or 'test' and the script will execute (without error) on all four tests sites (127.0.0.1, localhost, local and test). And of course statically setting $host to 'localhost' fails across all four. Any ideas? Again, I recently ran an update on my machine, which very well could have caused all of these problems. My next step will be to reinstall MySQL. Unfortunately I'm not exactly sure what the updates where. I do know that the issue came about sometime within the past four days as last friday my sandbox was working fine. Thanks in advance!