Apache – Localhost is not working

apachehostslocalhostwampxampp

I spend a day this issue, and I can't fix it.

Everytime I try to access to my localhost or by typing 127.0.0.1, the browser that I'm using is returning an error like : "Firefox can not find the server address at www.localhost.com."(i'm french, I translated the issue).

The same issue occures in Google Chrome and with 127.0.0.1. I tried with XAMPP and WAMP, still nothing. My Apache httpd.conf seems good, I tried to change the port (8080, 81, 8800). It still not working. My Skype is not open nether VMware Workstation. There is no program blocking the access to port 80 or 443.

I've made a ping test with the localhost and everthing is ok, but I can't access the index page of WAMP or XAMP.

The weird thing is that I can access to localhost/phpmyadmin and other pages like that.

I think my problem is in the hosts file of Windows, but it seems ok to me :

# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
# 102.54.94.97 rhino.acme.com # source server
# 38.25.63.10 x.acme.com # x client host

# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost

127.0.0.1 localhost

::1 localhost

Why am I thinking of the hosts file? Because my vhost in XAMPP and in WAMP are not working. Maybe I'm wrong, but this problem is driving me crazy!

Thanks for the help

Best Answer

If you have defined Virtual Hosts, and thats a very good idea, then you need to define the vhosts name in the HOSTS file.

For example, the hosts file:

127.0.0.1 localhost
::1 localhost

127.0.0.1 vhost1.dev
::1 vhost1.dev

127.0.0.1 vhost2.dev
::1 vhost2.dev

Otherwise windows has no way of knowing where to look for them.

Another possibility for localhost not working is a corrupted HOSTS file. Try deleting it and recreating it with an editor that is not notepad.

Also when you change the HOSTS file you need to restart the dmscache service 'DNS Client' by either rebooting or better still run a command window using "Run as Administrator" and do this

net stop dnscache
net start dnscache

that activates the new entries in your hosts file.

Related Topic