Can't access http://localhost on Vista

I am working with Head First’s “PHP & MySQL” book, and following along in the appendix for installing the development environment on my local machine. I installed MySQL, PHP, and Apache successfully. When I enter “http://localhost” in a browser, all I get is a browser error. I made the small test PHP script that the book shows and put it in C:\Inetpub\wwwroot but of course can’t execute the script because I can’t access localhost.

I didn’t even have the Inetpub folder on my machine until I followed another on-line tutorial for activating the Vista server on my local machine. I followed their steps (it was geared at turning on IIS) and now have the Inetpub folder, but it appears there’s much more setup I still need to do, or something I missed. After reading other Sitepoint posts, I see that Windows Vista is a big part of my problem, but all the same can someone help to get things operating right with my Vista environment? Any tech help needs to be written for a complete newbie who is unfamiliar with going into the windows environment and making behind the scenes changes. Thanks in advance.

You may want to switch to Apache instead of IIS. The majority of the servers running PHP current run under Apache. Installing Apache, MySQL and PHP is as simple as running 3 installers, so you might want to give it a try – if you can’t get IIS working >.>

Thanks for the quick reply but apparently my original post wasn’t clear. I did install Apache and it’s this that I can’t get working. My reference to IIS was only in that I followed a tutorial for turning on the Vista Server on my local machine which was geared at IIS, and when turned on allowed me to see the Inetpub\wwwroot folder finally. But I am trying to figure out how to work with Apache. I cannot access http://localhost even after installing Apache, MySQL and PHP. Thanks again.

PHP + IIS 7 on Windows Vista SP1, nothing easier then reading the documentation at the official IIS website.

Using FastCGI to Host PHP Applications on IIS 7.0

Guys thanks for the help. However, what I’m trying to do is work with Apache, not IIS. Am I going to be able to use the Apache server that I just installed on my machine? I can’t access http://localhost now that I’ve installed it. My system tray icon shows that all Apache services are running, but I still get a browser error.

Do this the easy way… take all the stuff you installed back off, and then get XAMPP or [url=]WAMP.

try going to does it work? If it doesn’t you may need to check if the service is actually running.

Well, actually I did that too. I started with the individual programs, then when that failed I picked up on the WAMP tip by reading other posts, so I uninstalled everything and installed WAMP. WAMP would not run, and I still couldn’t access http://localhost. I uninstalled WAMP and went back to the original three programs and began asking for help on this forum. I’m still wondering if I can use Apache with Windows Vista. Anyone know?

Oops, I didn’t see the tip about going to! I clicked on that and it worked! What does this mean?

That means apache is running >.>… You don’t by chance have a firewall running do you? If so, kill the firewall temporarily and check if http://localhost works. If that works, you may need to open up port 80 in your firewall.

C:\Windows\System32\drivers\etc, open “hosts”, check to make sure localhost is pointed to or that it is not commented out.

Go to Windows->System32->drivers->etc and open the hosts file using Wordpad.

The file should contain the following under the commented out description section:       localhost
::1             localhost

If those lines are not there add them to to the file and save the file. You may need to change the file permissions in order to save the file.

Or copy to the desktop, then move it back after the changes have been made. Or start notepad with admin rights then open the files from there.

Vista has a habit of mapping localhost to IPv6 instead of IPv4, so you need to set up IIS or Apache or whatever you’re using to bind ports on both IPv6 and IPv4 to get localhost to work :slight_smile:

Hey thanks everyone for jumping in on this. However, I turned off Windows Firewall, but got the same result. I also went into C:\Windows\System32\drivers\etc\hosts, then opened hosts with notepad, and found out that the local host was exactly as the previous posts indicated they’d be.

Thanks so much for these tech tips. Can you next tell me how to do this with Apache?

Check in C:\Windows\system32\drivers\etc\HOSTS file for the IPv6 setting (open and edit the HOSTS file by dragging it into a text editor).

Find this IPv6 line:
::1 localhost

Comment it out so it looks like this:

::1 localhost

Make sure the first uncommented line is: localhost

Save the file, restart Apache and then try to access your localhost again.

This is so much appreciated everyone! What a wonderful resource. I made the changes to the host file, and now when I go to http://localhost, I actually get “IT WORKS!” returned to me.

So now…I have a PHP script called “test.php” in C:\Inetpub\wwwroot which contains:

<?php phpinfo(); ?>

This script doesn’t execute when I go to http://localhost, I just get the above mentioned “IT WORKS!” I then went to http://localhost/test.php and the results were that I received a page back that said “<?php phpinfo(); ?>”

Is C:\Inetpub\wwwroot the actual file that localhost points to, or should I be putting my scripts in a different spot? Thanks!

Your going to need to alter you httpd.conf file to forward files with extention .php to the php interpreter. Though, the PHP installer does this for you. Have you already installed PHP?

Yes, PHP is installed, and I have seen the httpd file so I can get into that fine. I looked in once but it’s all greek to me at this early stage in my development. Can you be more specific on how to alter the file so as to send .php files to the interpreter?