403 Forbidden Error when trying to view localhost on Apache

4

3

I think my Apache must be all screwed up. I don't know if it ever worked. I just upgraded to Snow Leopard, and the first step on this tutorial is to start apache and check that it's working by opening http://localhost. It starts fine but when I go to localhost I get a 403 forbidden error.

I don't know where to start figuring out how to fix it, so I wonder if a fresh install of Apache would do the trick.

What do you think?

Update: I found some error logs in /private/var/log/apache2/. Found this in one of the logs. Not sure what it means:

[Tue Nov 10 17:53:08 2009] [notice] caught SIGTERM, shutting down
[Tue Nov 10 21:49:17 2009] [warn] Init: Session Cache is not configured [hint: SSLSessionCache]
Warning: DocumentRoot [/usr/docs/dummy-host.example.com] does not exist
Warning: DocumentRoot [/usr/docs/dummy-host2.example.com] does not exist
httpd: Could not reliably determine the server's fully qualified domain name, using Andrews-Mac-Pro.local for ServerName
mod_bonjour: Skipping user 'andrew' - cannot read index file '/Users/andrew/Sites/index.html'.
[Tue Nov 10 21:49:19 2009] [notice] Digest: generating secret for digest authentication ...
[Tue Nov 10 21:49:19 2009] [notice] Digest: done
[Tue Nov 10 21:49:19 2009] [notice] Apache/2.2.11 (Unix) mod_ssl/2.2.11 OpenSSL/0.9.8k DAV/2 PHP/5.3.0 configured -- resuming normal operations

Update: I also found something in the dummy-host.example.com-error_log file. I didn't set these dummy-host things by the way. Is this the default configuration?

[Tue Nov 10 21:59:57 2009] [error] [client ::1] client denied by server configuration: /usr/docs

Update: Woohoo! I found the file that had the virtual host definitions. It was in /etc/apache2/extra/httpd-vhosts.conf. It had those two dummy virtual host settings in there. I added a localhost virtual host. Not sure if this is necessary, but since it wasn't working before, decided to do it anyway. After removing the old virtual hosts, adding my new localhost virtual host, and restarting apache, it seems to work. So I guess whenever I want to add a virtual host, I only need to add them to this file? Or is there a hosts file somewhere, like there is on Linux?

Update: Yes, there is an /etc/hosts file that need to be changed to. Add the virtual host name to that file.

Andrew

Posted 2009-11-11T06:11:34.553

Reputation: 11 982

There is a more updated answer here: http://superuser.com/questions/200223/using-xampp-error-403-access-forbidden

– Doug – 2010-10-16T23:34:28.650

please accept your own answer? This question just got bumped by community to give it some attention, but it seems it doesn't need it?

– Arjan – 2010-12-04T13:01:04.170

So wait, you've solved it? – random – 2009-11-11T07:56:52.033

Yes, I think I did – Andrew – 2009-11-11T16:59:42.573

Answers

2

If you're getting a 403 error it probably means the directory does not exist, or the privileges on that directory won't let you see it.

My problem was that the default virtual host settings were pointing to a directory that didn't exist.

So here's what you should do: (assuming you're on Snow Leopard)

  1. Find and open your virtual hosts configuration file.

    pico /etc/apache2/extra/httpd-vhosts.conf
    
  2. Check that your virtual host definitions are in there, otherwise create them

    <VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot "/Users/yourusername/Sites/mysite"
    ServerName mysite.local
    ErrorLog "/private/var/log/apache2/mysite-error_log"
    CustomLog "/private/var/log/apache2/mysite-access_log" common
    </VirtualHost>
    
  3. Open up /etc/hosts file and add your virtual host name. This is what's in mine:

    ##
    # 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
    255.255.255.255    broadcasthost
    ::1                localhost 
    fe80::1%lo0        localhost
    
    # VIRTUAL HOST START
    127.0.0.1          localhost
    127.0.0.1          mysite.local
    # VIRTUAL HOST STOP
    
  4. Now restart Apache and you should be good to go!

    sudo apachectl restart
    

Andrew

Posted 2009-11-11T06:11:34.553

Reputation: 11 982

@Andrew doesn't the second 127.0.0.1 localhost entry simply repeat the one above, or are both necessary? – YPCrumble – 2015-04-14T20:54:53.853

Where do I input that command to restart apache? – Doug – 2010-10-16T22:52:03.670

in a terminal window – Andrew – 2010-12-06T15:45:45.627

0

Also it is labeled as a warning, it is really the critical line in your error log:

Warning: DocumentRoot [/usr/docs/dummy-host.example.com] does not exist

Apache is searching for a directory that will hold the files that will be solved when you talk to it. Apparently, this directory doesn't exist and thus Apache is not able to solve you anything. Create the directory and place some index.html file in there or edit your config file to point Apache to another directory.

innaM

Posted 2009-11-11T06:11:34.553

Reputation: 9 208