Search code examples
apachemacos-sierra

Apache - You don't have permission to access / on this server


At clg.localhost/ I'm getting error:

You don't have permission to access / on this server.

But, following this, I've set up my Apache httpd.conf and sites.conf to allow access with AllowOverride all and Require all granted. What else am I missing?

Versions:

$ /usr/sbin/httpd -v
Server version: Apache/2.4.23 (Unix)
Server built:   Aug  8 2016 18:10:45

Apache httpd.conf:

DocumentRoot "/Users/danniu/Sites"
<Directory "/Users/danniu/Sites">
    #
    # Possible values for the Options directive are "None", "All",
    # or any combination of:
    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
    #
    # Note that "MultiViews" must be named *explicitly* --- "Options All"
    # doesn't give it to you.
    #
    # The Options directive is both complicated and important.  Please see
    # http://httpd.apache.org/docs/2.4/mod/core.html#options
    # for more information.
    #
    Options FollowSymLinks Multiviews
    MultiviewsMatch Any

    #
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   AllowOverride FileInfo AuthConfig Limit
    #
    AllowOverride all

    #
    # Controls who can get stuff from this server.
    #
    Require all granted
</Directory>

...

#
# Deny access to the entirety of your server's filesystem. You must
# explicitly permit access to web content directories in other 
# <Directory> blocks below.
#
<Directory />
    AllowOverride all
    Require all granted     
</Directory>

Apache sites.conf:

# Workaround for missing Authorization header under CGI/FastCGI Apache:
<IfModule setenvif_module>
  SetEnvIf Authorization .+ HTTP_AUTHORIZATION=$0
</IfModule>

# Serve ~/Sites at http://localhost
ServerName localhost

<VirtualHost *:80>
   ServerName clg.localhost
   DocumentRoot /Users/danniu/Sites/CLG/CLG-dev
</VirtualHost>

I thought perhaps httpd.conf wasn't properly being picked up, so I specified the root directly in the Virtual Host, with the same issue.

<VirtualHost *:80>
   ServerName clg.localhost
   DocumentRoot /Users/danniu/Sites/CLG/CLG-dev
   # Set access permission
   <Directory "/Users/danniu/Sites/CLG/CLG-dev">
     Require all granted
  </Directory>
</VirtualHost>

Solution

  • / is a directory, so if you don't have an index file pointed to with DirectoryIndex, such as index.html, and you don't have Indexes enabled, as you don't, Apache can't show contents of your documentroot.

    Note you have Options FollowSymLinks Multiviews

    The solution, to the Options add Indexes like follows for "directory listing" (this depends on mod_autoindex being loaded previously):

    Options FollowSymLinks Multiviews Indexes
    

    If you want a default file loaded, for example index.html, DirectoryIndex by default looks for index.html, so add it, or if something its overriding its behaviour somewhere else do:

    DirectoryIndex index.html