Laravel 5.4 on Heroku. Forbidden You don’t have permission to access / on this server

I have deployed my laravel 5.4 app on Heroku. The problem is, I am getting this error message:

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

My Procfile:

web: vendor/bin/heroku-php-apache2 public/

Looking into the log, I find that it has been trying ‘app/’ instead of ‘/’.

My log, snipped for readability.

2017-12-03T14:18:45.747195+00:00 app[web.1]: [Sun Dec 03 14:18:45.746749 2017] [autoindex:error] [pid 122:tid 140692458305280] [client 10.140.221.43:41026] AH01276: Cannot serve directory /app/: No matching DirectoryIndex (index.php,index.html,index.htm) found, and server-generated directory index forbidden by Options directive

My .htaccess:

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]

    # Handle Authorization Header
    RewriteC

I can’t figure out where i might be saying it to look into ‘app/’ instead of ‘/’. If that is the cause for this error.

Answer

I don’t know why the server thinks your root is at /app but this error occurs because of the permission of the public/ directory from which Heroku is supposed to serve your application.

To resolve this issue, simply add the following to the script section of your composer.json

 "post-install-cmd": [
     "php artisan clear-compiled",
     "chmod -R 777 public/"
 ]

Note the change in permission of the public/ directory.

EDIT:

While you are at it, check your Procfile make sure it is spelled correctly and starts with an uppercase P.

PS: I know some people are really nitpicky and would say the permission is too lax. Yes, I agree with you. You can change it to something else like 775 let’s just get the juice flowing.

Leave a Reply

Your email address will not be published. Required fields are marked *