# 127.0.0.1 is working but localhost is not working on mac XAMPP

I installed XAMPP on my mac months ago and was working great.

Now i get "Test Page For Apache Installation" when i try to browse /localhost

But when i browse /127.0.0.1 it just works as localhost used to be.

I double checked my /etc/hosts file that i have 127.0.0.1 localhost and not commented.

Also when i browse localhost/~username/test.php , i get contents of test.php:

<?php echo 'ganim'; ?>


but if i browse 127.0.0.1/~username/test.php , i get:

ganim


what could change redirecting of localhost or how can i get localhost work again?

-

## migrated from stackoverflow.comOct 20 '09 at 3:14

This question came from our site for professional and enthusiast programmers.

The 'Test Page for Apache installation' IS the webpage served when you access localhost, so that part's working. If that's not what you had before, something has changed the files in the document root. –  pavium Oct 20 '09 at 2:48
I used to see XAMPP's orange page when i browse for localhost also i couldn't find the 'Test Page for Apache installation' file on hard drive and ist it weird that i have XAMPP's page on 127.0.0.1 but i get 'Test Page for Apache installation' on localhost... –  Ganim Oct 20 '09 at 3:09

Maybe the OS X built-in web server is active and managed to bind to localhost, while XAMPP managed to bind to 127.0.0.1? Try turning off Web Sharing in System Preferences and restart XAMPP.

-
That doesn't make much sense, since localhost=127.0.0.1. –  Tarnay Kálmán Oct 20 '09 at 2:57
does /etc/hosts exist in Mac world? Cause you can change that definition –  PostMan Oct 20 '09 at 3:01
Well, i didn't remember that i turned on Web Sharing, i turned it off and everything turned back to normal. Thanks. –  user23416 Oct 20 '09 at 3:30
@Kalmi: Apparently it did make sense after all. :) Recently localhost tends to mean ::1 on Macs. –  deceze Oct 20 '09 at 3:34

try to ping localhost, see if it maps to 127.0.0.1. In my case, my Mac maps localhost to 127.0.0.1.

-
That's actually not a good test because ping doesn't handle IPv6. You can try telnetting to localhost; at least in 10.6 I see it try ::1, then fe80::1, then finally 127.0.0.1. –  Nicholas Riley Oct 20 '09 at 3:01

localhost first tries the IPv6 localhost (::1) and you're probably not considering that in your Apache config. You can test by disabling IPv6 for the loopback interface:

% sudo ip6 -d lo0
% ifconfig lo0
lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384
inet 127.0.0.1 netmask 0xff000000


Then try localhost again; it should only be able to connect via IPv4. (Note that many Mac OS X features use IPv6, so this is not a long-term solution, just a diagnostic measure. You should fix your Apache configuration.)

-

The reason this occurs is because of the way Mac handles urls. I'm assuming you want this to show up in Safari and that you want it enabled via Web Sharing preferences panel of the Preferences pane. If so do this.

1.) Verify that the following line is in /etc/hosts 127.0.0.1 localhost

2.) Verify XAMPP is starting on port 80 or determine which port it is starting on and verify that you are looking at http://127.0.0.1:

Now comes the fun.. This looks like PHP so...

3.) Make sure the following line is enabled in /etc/apache2/httpd.conf (default it is)

LoadModule php5_module        libexec/apache2/libphp5.so


4.) Make sure that the users space area is enabled int /etc/apache2/httpd.conf

Include /private/etc/apache2/extra/httpd-userdir.conf


5.) Ensure that your username is listed /private/etc/apache2/users/*.conf There should be a file with your username in it. It should contain something like this..

<Directory "/Users/<username>/Sites/">
Options Indexes MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>


6.) Restart web sharing and go to http://localhost/~username

Enjoy.

-