I've successfully used PHP/Apache/MySQL on my iMac several times in the past few months/years. However, I started using a new PHP book and moved things around a bit (obviously without knowing what I thought I was doing!) I managed to get localhost working about a week ago. I had to stop work on this project until late today. Once again, using a saved bookmark for phpMySql today, I got the infamous "cannot connect to localhost." message.
To make this somewhat shorter, I can now access localhost again. Whew! Here's my hosts file:
10.0.1.2 localhost 255.255.255.255 broadcasthost ::1 localhost # fe80::1%lo0 localhost
Firstly, I have no idea what that last, commented out line is for, but I'll search the net after posting this.
Secondly, the 10.0.1.2 used to appear in the "Web Sharing" Pref Panel. Now it has my computerName/~username.
Finally, although localhost is working (and I changed the bookmark for it),
apachectl -t shows this response:
httpd: Could not reliably determine the server's fully qualified domain name, using ::1 for ServerName
I thought from reading that this indicated the use of IPv6 but turning that OFF in Network PP doesn't seem to make any difference in the response from Apache.
As you can see, I know just enough to be dangerous, fortunately only to myself, I hope!