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

大憨熊 提交于 2019-12-10 13:56:14

问题


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.


回答1:


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.




回答2:


/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.




回答3:


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 =)




回答4:


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



来源:https://stackoverflow.com/questions/47619860/laravel-5-4-on-heroku-forbidden-you-dont-have-permission-to-access-on-this-s

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!