403 Forbidden, Index of / catch 22

I’m having a really rough time on this one and have tried a ton of solutions which have worked for certain people but not for me. Firstly my set up:
Ubuntu 14.04.2
Apache 2.4.7

I’m currently migrating my site to wordpress into the folder structure /var/www/dev which is set up as a virtual host – dev.conf looks like:

Read More
<VirtualHost *:80>
    # The ServerName directive sets the request scheme, hostname and port that
    ServerAdmin ubuntu@12.345.678.90
    DocumentRoot /var/www/dev
    ServerName dev.mysite.com

    <Directory />
            Options FollowSymLinks
            AllowOverride All
    </Directory>
    <Directory /var/www/dev/>
            Options -Indexes +FollowSymLinks
            AllowOverride All
            #Require all granted
            Order allow,deny
            allow from all
    </Directory>
</VirtualHost>

My problem is that when I access my home page in a browser for the first time dev.mysite.com it directs me to a 403 page:

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

I also have an .htaccess file in my root folder that looks like this currently:

DirectoryIndex index.php index.html
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

I followed 2 different sets of advice so far – one saying to change my config Option to:

Options +Indexes

However when i navigate to my home page it gives me the physical folder “Index of /” with a list of all my files and folders – which I don’t want. So I’ve left it as

Options -Indexes

Another set of advice said add this to the htaccess file:

DirectoryIndex index.php index.html

I’ve also checked my folder permissions, all owned by my apache user admin ubuntu:ubuntu and all follow the standard wordpress folder permissions e.g. all folders are 755 all files are 644 (rough rule of thumb).

I’ve also tried as you can see (commented out above) using the new apache 2.4 standard

Require all granted 

instead of

Order allow,deny
allow from all

I’m also restarting the server every time I make a change so nothing silly like that. What am I doing in the above config that’s not letting me load my site?

Specifically my homepage goes to 403 Forbidden, any other page e.g. dev.mysite.com/features loads this error message:

User-agent: *
Disallow: /wp-admin/

EDIT:
The above issues only occur when the url is loaded initially – if I refresh the page it loads as it should.

Here’s my file ownership structure – perhaps this may provide useful:

-rw-rw-r--  1 ubuntu   ubuntu       350 Sep 26 19:35 .htaccess
-rw-rw-r--  1 ubuntu   ubuntu      4951 Sep  9 13:21 wp-activate.php
drwxrwxr-x  9 ubuntu   ubuntu      4096 Sep  9 13:21 wp-admin
-rw-rw-r--  1 ubuntu   ubuntu       271 Sep  9 13:21 wp-blog-header.php
-rw-rw-r--  1 ubuntu   ubuntu      5007 Sep  9 13:21 wp-comments-post.php
-rw-rw-r--  1 ubuntu   ubuntu      3130 Sep 24 10:32 wp-config.php
-rw-rw-r--  1 ubuntu   ubuntu      2764 Sep 16 17:23 wp-config-sample.php
drwxrwxr-x  6 ubuntu   ubuntu      4096 Sep 24 10:46 wp-content
-rw-rw-r--  1 ubuntu   ubuntu      3286 Sep 16 17:23 wp-cron.php
drwxrwxr-x 12 ubuntu   ubuntu      4096 Sep  9 13:21 wp-includes
-rw-rw-r--  1 ubuntu   ubuntu      2380 Sep  9 13:21 wp-links-opml.php
-rw-rw-r--  1 ubuntu   ubuntu      3123 Sep  9 13:21 wp-load.php
-rw-rw-r--  1 ubuntu   ubuntu     34669 Sep 16 17:23 wp-login.php
-rw-rw-r--  1 ubuntu   ubuntu      8252 Sep  9 13:21 wp-mail.php
-rw-rw-r--  1 ubuntu   ubuntu     11062 Sep 16 17:23 wp-settings.php
-rw-rw-r--  1 ubuntu   ubuntu     25124 Sep 16 17:23 wp-signup.php
-rw-rw-r--  1 ubuntu   ubuntu      4035 Sep  9 13:21 wp-trackback.php
-rw-rw-r--  1 ubuntu   ubuntu      3055 Sep 16 17:23 xmlrpc.php

Related posts

1 comment

  1. Forbidden 403 simply means that there is some problem with permissions. When server is trying to access the requested resource then it is being restricted due to permission issues, so those who were advising on modifying Indexes weren’t even close because Indexes option is to control the directory listing. Below is excerpt about Indexes option from Apache

    If a URL which maps to a directory is requested and there is no
    DirectoryIndex (e.g., index.html) in that directory, then
    mod_autoindex will return a formatted listing of the directory.

    Clearly root cause of your issue is “permissions”.

    Now, for the solution part – since I don’t know your all the content of your .htaccess and dev.conf, so below your be my step by step approach:

    1. Try below code snippet. I am trying to disable your .htaccess files effect and see if that’s root cause. If it works then you to review all the content of your .htaccess for possible issue.

      <Directory /var/www/dev/>
              Options -Indexes +FollowSymLinks
              AllowOverride None
              Order allow,deny
              allow from all
      </Directory>
      
    2. Try below code snippet. Default Apache access for Directory is Allow from All, so I am removing it and let default take effect and no ordering .. Anyways you were also trying same thing ..

      <Directory /var/www/dev/>
              Options -Indexes +FollowSymLinks
              AllowOverride All
      </Directory>
      

    On a side note, I would suggest that first try to do chmod 777 for your web app directories and files, because in most cases permission issue is because of UNIX permissions and not Apache permissions.


    Followup edit:
    For further debugging we will need server error info, can you enable maximum debugging and get the content from error.log and access.log (if HTTPS access then from ssl log). Reference

    Also, could you please provide context of DirectoryIndex directive and URL you are using.

    All odds are that you have permission issue, may be because of Apache or UNIX.

    So, lets first comprehensively rule out UNIX permissions issue, so momentarily try out chmod 777 for your web app resource, if it works we know it is UNIX permission issue and we will see what to do next.

    I am getting skeptical about RewriteBase / and RewriteRule . /index.php [L] in your .htaccess file .
    Give a try to RewriteBase /var/www/dev or whatever you think could be more relevant but NOT /
    Also, try to play around with RewriteRule, so instead try absolute path of index.php, so use RewriteRule . /var/www/dev/<<XYZ>>/index.php

    Give a try using exact below, if you don’t have mod_cgi module included then you may need to.

    <Directory "/home/domain/www">
            Options +Indexes FollowSymLinks +ExecCGI
            AllowOverride All
            Order allow,deny
            Allow from all
    </Directory>
    


    Final solution:

    For those who are looking for solution – once OP recursively granted permission using chmod -R www:data, he could solve this issue. So, to conclude – this issue was not because of Apache configuration but because of UNIX permissions. Read OP’s comments below for more details.

Comments are closed.