Sijan Bhattarai
Sijan Bhattarai

Reputation: 650

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.

Upvotes: 20

Views: 63427

Answers (12)

Abdallah
Abdallah

Reputation: 89

Edit the Procfile

from

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

to

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

Upvotes: 1

Jameesjohn
Jameesjohn

Reputation: 89

If anyone is still having this issue, ensure that the procfile is named Procfile with the capital P.

Upvotes: 1

Mexan KABA
Mexan KABA

Reputation: 11

I removed the quotation mark that surrounded the text of the procfile file and it works

Upvotes: 1

I created Procfile using echo "web: vendor/bin/heroku-php-apache2 public/" > Procfile command just like the docs told me to, but then it generated the Procfile command inside a quotation mark. That's why, I still get the 403 forbidden error even though I've modified my composer.json file just like the other user suggested to.

So guys, make sure the command inside your Procfile isn't surrounded by quotation mark. Then, modify the composer.json just like the approved answer suggested to and re-deploy your site.

Upvotes: 0

Maksudul Haq
Maksudul Haq

Reputation: 61

SOLUTION STEPS:

  1. Clone your project to your PC: heroku git:clone -a your-app-name

  2. Create a file name: Procfile

  3. Then save following lin of code in this Procfile: web: vendor/bin/heroku-php-apache2 public/

  4. Deploy your project back to heroku using commed: $ git add . $ git commit -am "make it better" $ git push heroku master

  5. I hope now no problem run your Laravel App!

Upvotes: 6

optimus
optimus

Reputation: 65

I faced the same problem when deploying my Laravel app on Heroku. I tried to change permissions in/of my composer file, but that didn't help. Instead, I added this to my htaccess file:

<IfModule dir_module>
    DirectoryIndex index.html index.php
</IfModule>

Pushing this to Heroku fixed the problem.

Upvotes: 0

mirsahib
mirsahib

Reputation: 445

This error persist even though i have followed the answer which is marked correct (even i have run heroku run bash to ls -l to see the file permission) but i was still getting this error and may be this is because i was using different local branch rather than the local master branch so my advice is to always deploy from your local master branch and also when i deploy from another branch i get this log when pushing the code to heroku

 NOTICE: No Procfile, using 'web: heroku-php-apache2'

Upvotes: 0

Sage Gwatkin
Sage Gwatkin

Reputation: 41

I was having the same issue today, and have found an easy solution to it. I'm running a Laravel 6 app on Heroku.

The issue started after I setup an HTTPS redirect, by adding an apache configuration file, and loading it using the -C option in the Heroku Procfile:

web: vendor/bin/heroku-php-apache2 -C apache.conf public/

The error I was receiving:

2020-01-13T03:55:29.272349+00:00 app[web.1]: [Mon Jan 13 03:55:29.271704 2020] [autoindex:error] [pid 127:tid 140227477751552] [client 10.213.231.122:26179] AH01276: Cannot serve directory /app/public/: No matching DirectoryIndex (index.html) found, and server-generated directory index forbidden by Options directive

So the same issue as you were having. What I found was that when you start apache with a custom configuration on Heroku, it starts looking for an index.html file, instead of an index.php file.

To fix this, I added the following line to my apache configuration file:

DirectoryIndex index.php

This directs apache to look for index.php, and fixes the issue.

Upvotes: 1

Pila
Pila

Reputation: 5842

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.

Upvotes: 33

Mikayel Margaryan
Mikayel Margaryan

Reputation: 794

Inside the Laravel Root folder, make a file called Procfile.

Write the following line inside the Procfile.

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

Then deploy it again! Src and more here https://appdividend.com/2018/04/17/how-to-deploy-laravel-project-on-heroku/

Hope this was helpful =)

Upvotes: 12

Abubakr Elghazawy
Abubakr Elghazawy

Reputation: 985

Create and put this .htaccess file in your laravel installation folder.

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>

solution is Here:enter link description here

Upvotes: 3

dzuelke
dzuelke

Reputation: 2645

/app is the absolute path on the file system, where you app resides. The error indicates that your Procfile does not actually contain what you claim it does. You probably haven't added and committed it to Git. Apache is trying to serve from the "root" right now, not from the public/ subdirectory.

Upvotes: 3

Related Questions