I was developing a new website that uses Facebook Login as the membership system. I came across this situation where I needed to create a “fake” domain by editing the etc/hosts file. Somehow, after editing the etc/hosts file (following an online guide), I cannot seems to browse http://localhost in my browser anymore. However, I can still browse my local apache server using http://127.0.0.1
This is not XAMPP / apache issue
This is not browser-specific issue
In fact, this is a simple problem with simple solution. However, this problem occurs when I am getting frustrated with the Facebook integration problem (after 12 hours of debugging). Therefore, I missed some simple but important steps to solve this problem. Here I list them down below:
For Mac OS users, open up your Terminal. For windows users, open up your command prompt.
PING 127.0.0.1 (127.0.0.1): 56 data bytes 64 bytes from 127.0.0.1: icmp_seq=0 ttl=64 time=0.118 ms 64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.171 ms 64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.167 ms
Modern browsers cache a lot of stuff, including DNS cache. They may have cached the erroneous DNS setting in etc/hosts, so you might want to clear your browsers cache and try loading localhost again. Clearing cache alone would already be sufficient, you can skip clearing cookies, saved session, etc.
If it still doesn’t work, try #3 below.
I ran this command in terminal (Mac) to flush my cache before I get into this mess: “dscacheutil -flushcache”
For some reason, after I flushed the cache, the DNS setting is not being rebuilt – I cannot ping localhost but I can ping 127.0.0.1
After restarting my laptop (to rebuild the DNS settings & cache) and clearing all browser cache once again, I finally get my localhost displayed again.
Now I hope this helps some of you.