localhost and 127.0.0.1 doesn't get the same page - php

It will show different page when I visit localhost and 127.0.0.1 , I don't know what happened.
My hosts has bind 127.0.0.1 and ::1 to localhost. Like this:
127.0.0.1 localhost
::1 localhost
When I visit localhost it is ok. It shows me the index.php which in the root dir. I want to know why localhost and 127.0.0.1 get the difference page and which file 127.0.0.1 visited?
I use wnmp.
ps: when I ping localhost, it shows me ::1.
Can anyone help?

Comment those out in host
# 127.0.0.1 localhost
# ::1 localhost
It is predefined already. It is not possible that they are showing different pages since they point to your local ip and the same port 80. Is your wamp fresh installed? you might have configured like the vhost.

Related

Wamp server not able access in internet after changing the port

I have changed the port number in apache in bitnami wamp stack by following changes in httpd.conf file.
Listen 8083
ServerName localhost:8083
After changing the server is not able to access in interenet. In localhost it is showing the home page.
I have added the :8083 after the ip address.Can anyone please help on this?
You don't need ServerName localhost:8083 just ServerName localhost. In browser:
localhost:8083

Error 404 on localhost with wampserver

I've been using wamp for 2 weeks at my work without any problem, but now I've some issues :
localhost/phpmyadmin is working well, but
localhost/ and 127.0.0.1 gives me a 404 error :
Not Found The requested URL / was not found on this server.
I already tested the port 80 and it's used by Apache.
I have virtual hosts that works well but I can't create a new one anymore, it won't work, I don't know why.
I've searched a lot on internet but all I can find is solution that just does not work for me so if you could help me, that would be fantastic.
EDIT : I just changed my httpd-vhosts.conf, I had a mistake in my new vhosts, so now they work well, but I still have an error 404 on localhost/.
EDIT : Thank you RiggsFolly for the help, I needed to had localhost in my httpd-vhosts.conf
Ok, this sounds like the browser is trying to use the IPV6 network but you have not entered the IPV6 loopback address into the hosts file
Amend your hosts file to be
127.0.0.1 localhost
127.0.0.1 other.dev
127.0.0.1 other2.dev
::1 localhost
::1 other.dev
::1 other2.dev
The ::1 is the IPV6 loopback address just as 127.0.0.1 is the IPV4 loopback address.
You say you have Virtual Hosts setup, did you also define one, the first one for localhost. Once a Virtual Host is defined the default in httpd.conf for localhost is ignored.
So add this to the top of httpd-vhosts.conf
<VirtualHost *:80>
ServerName localhost
DocumentRoot c:/wamp/www
<Directory "c:/wamp/www/">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require local
</Directory>
</VirtualHost>
Change c: to whatever drive you installed WAMPServer onto.

127.0.0.1 is accessible/working but localhost not accessible/ not working

I am using wamp for few years and i upgraded to windows 8 few months before, my wamp working smoothly up to yesterday. But now it can't be accessed using localhost. but when i trying 127.0.0.1 instead it works smoothly. I changed ::1 localhost to 127.0.0.1 localhost in host file. which where the solution suggested for this problem in most websites. But unfortunately its not work for me. When i ping localhost its showing replay from ::1: time<1ms. And There is no software's using port 80 i already checked it. please help to solve this.
Mine is Ubuntu 20.04 VM
I had this following line.
::1 localhost ip6-localhost ip6-loopback
I commented that line and added the following line.
::1 ip6-localhost ip6-loopback
Basically removed
::1 localhost
It now works.
The final look of the hosts file is as follows.
127.0.0.1 localhost
127.0.1.1 vagrant.vm vagrant
# The following lines are desirable for IPv6 capable hosts
#::1 localhost ip6-localhost ip6-loopback
::1 ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
127.0.2.1 w1 w1
Edit
%SystemRoot%\system32\drivers\etc\hosts
and replace
::1 localhost
with
127.0.0.1 localhost
Save and restart apache.
Hope it will work .
Add 127.0.0.1 localhost to your hosts file.
If there is a # (comment sign) in front of it, remove it.
Remove other instances of localhost, or place a # in front of those other instances.
Your hosts file is usually in c:\windows\system32\drivers\etc\hosts, and when you try to edit this file run notepad (or any other preferred editor) as ADMINISTRATOR, otherwise chances are big your modifications wont be saved.
After doing all this, in your browser do a control-f5 (refresh without using the cache).
For DNS problem:
ipconfig /flushdns
ipconfig /registerdns
or rather backup the code and reinstall the wamp server.
Much faster solution however remember you're wamp settings.
Resolved Issue by editing /etc/hosts file:
I also had similar issue(Able to ping 127.0.0.1, but issue while pinging localhost). I resolved it by removing
entries like
::1 localhost, ff81::1%lo0 localhost
with only 127.0.0.1 localhost....
I removed rest of the entries for localhost. I done this for my mac.
After this process I can debug my java application using eclipse.
You can remove comment (# row start) or add
127.0.0.1 localhost
In your hosts (folder etc)
Open this file with privilege admin
This issue also arises if you edited your vhosts.conf file and added a virtual host. To resolve comment out every line of the virtual host entry, e.g.
If using xampp, edit your entry in vhosts.conf and comment all the lines (add an # before each line)
##<VirtualHost *:80>
##ServerAdmin webmaster#dummy-host.example.com
##DocumentRoot "E:/xampp/htdocs/dummy-host.example.com"
##ServerName dummy-host.example.com
##ServerAlias www.dummy-host.example.com
##ErrorLog "logs/dummy-host.example.com-error.log"
##CustomLog "logs/dummy-host.example.com-access.log" common
##</VirtualHost>
then un-comment or add 127.0.0.1 localhost in your hosts file.
I ran into the same problem with XAMPP on my Mac and (finally) figured out how to fix it. Something similar might work for you on Windows:
Even though my /etc/hosts file looked correct, I had a feeling it wasn't working. ("ping localhost" returned no results, but "ping 127.0.0.1" was working.) So, I found that there was a copy of the original hosts file (/etc/hosts~orig) which I replaced my current hosts file with. That did the trick after restarting Apache.
$ sudo mv /etc/hosts /etc/hosts~old
$ sudo cp /etc/hosts~orig /etc/hosts
$ ping localhost
After adding the line 127.0.0.1 localhost to the hosts file, copy the contents of hosts file and paste it in another new file, then replace the old hosts files with the new one. This worked for me.

OSX Mavericks - Set up Apache with subdomains

I have successfully set up a local server running PHP on my Mac, but I am having trouble setting up extra local sites as subdomains (i.e. site2.localhost)
Here's what I have so far:
hosts file:
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
127.0.0.1 site2.localhost
255.255.255.255 broadcasthost
::1 localhost
fe80::1%lo0 localhost
httpd-vhosts.conf:
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot "/Users/user/Sites/site2"
ServerName site2.localhost
</VirtualHost>
and I've uncommented the following line in the httpd.conf file:
Include /private/etc/apache2/extra/httpd-vhosts.conf
I'm not sure what else I need to add or where I need to add it.
OK, seems as if I needed to look a little harder... It was in fact set up correctly, but for some reason when I typed site2.localhost into the browser it was defaulting to https.
By manually typing in http://site2.localhost it works fine.

Zend Server CE, After Uninstall, localhost doesn't work

This is odd...
I installed Zend Server to test it out. Turns out I don't like it and I wanted to go back to MAMP. But after the Zend Server CE uninstall, "localhost" no longer works. I can only access MAMP from 127.0.0.1
Frustrating and I'm not liking it at all.
Any ideas?
hosts:
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
fe80::1%lo0 localhost
127.0.0.1 mydomain.loc www.mydomain.loc
nslookup says:
Server: 64.59.160.13
Address: 64.59.160.13#53
Non-authoritative answer:
Name: localhost
Address: 127.0.0.1
I was told by a college that sometimes the only thing you can do to wake up port 80 on the Mac is to enable the built in web server and then disable it again.
So I did that and all is well.
you mention 127.0.0.1 which is a IPv6 address. Many (all?) modern operating systems are configured to resolve localhost using IPv6 to ::1. My assumption would be that your MAMP setup is not listening via IPv6. Try opening http://[::1]/ if that works there is an error in our resolve configuration, if not (what I expect) you have to configure your web server to either lsiten to ::1 or any device.
This can be done in httpd.conf using
Listen 80
to listen on all devices, port 80 or
Listen [::1]:80
to listen to localhost via IPv6 only. Mind not having conflicting VHost entries etc.

Categories