2

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

and /localhost/xampp is not found.

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?

2
  • 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, 2009 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, 2009 at 3:09

5 Answers 5

1

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.

4
  • That doesn't make much sense, since localhost=127.0.0.1. Oct 20, 2009 at 2:57
  • does /etc/hosts exist in Mac world? Cause you can change that definition
    – PostMan
    Oct 20, 2009 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, 2009 at 3:30
  • 2
    @Kalmi: Apparently it did make sense after all. :) Recently localhost tends to mean ::1 on Macs.
    – deceze
    Oct 20, 2009 at 3:34
3

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.)

2
  • 1
    I've comment ::1 localhost in /etc/hosts, it's now working !
    – Fabien Sa
    Dec 19, 2015 at 2:07
  • 3
    Keep in mind this may break a lot of other stuff, particularly in the future with more movement to IPv6. You should really fix the actual problem in your Apache configuration so it listens on v6 localhost. Dec 19, 2015 at 17:11
1

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.

1
  • 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. Oct 20, 2009 at 3:01
1

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.

0

If you have upgraded php version you'll have to reconfigure your httpd.conf file and restart your server, this will help

You must log in to answer this question.