php Heroku 上的 Laravel 5.4。Forbidden 您无权访问 / 在此服务器上

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/47619860/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 02:34:36  来源:igfitidea点击:

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

phpapacheherokularavel-5.4

提问by Sijan Bhattarai

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

我已经在 Heroku 上部署了我的 Laravel 5.4 应用程序。问题是,我收到此错误消息:

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

Forbidden 您无权访问 / 在此服务器上

My Procfile:

我的档案:

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

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

查看日志,我发现它一直在尝试使用“app/”而不是“/”。

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:

我的.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 ^(.*)/$ / [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.

我不知道我可能在哪里说要查看'app/'而不是'/'。如果这是导致此错误的原因。

回答by Pila

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

我不知道为什么服务器认为您的根在,/app但是由于public/Heroku 应该为您的应用程序提供服务的目录的权限而发生此错误。

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

要解决此问题,只需将以下内容添加到script您的部分composer.json

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

Note the change in permission of the public/directory.

注意public/目录权限的变化。

EDIT:

编辑:

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

当您使用它时,请检查您的Procfile拼写是否正确并以大写字母开头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 775let's just get the juice flowing.

PS:我知道有些人真的很挑剔,会说权限太松了。是的,我同意你的看法。您可以将其更改为其他内容,例如775让我们让果汁流动。

回答by Mikayel Margaryan

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

在 Laravel Root 文件夹中,创建一个名为 Procfile 的文件。

Write the following line inside the Procfile.

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

然后再次部署它!Src 和更多在这里https://appdividend.com/2018/04/17/how-to-deploy-laravel-project-on-heroku/

Hope this was helpful =)

希望这有帮助 =)

回答by dzuelke

/appis the absolute path on the file system, where you app resides. The error indicates that your Procfiledoes 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.

/app是文件系统上的绝对路径,您的应用程序所在的位置。该错误表明您Procfile实际上并不包含您声称的内容。您可能还没有将它添加并提交给 Git。Apache 现在正在尝试从“根”而不是从public/子目录提供服务。

回答by Sage Gwatkin

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

我今天遇到了同样的问题,并找到了一个简单的解决方案。我正在 Heroku 上运行 Laravel 6 应用程序。

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:

在我通过添加 apache 配置文件并使用 Heroku Procfile 中的 -C 选项加载它来设置 HTTPS 重定向后,问题开始了:

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.

所以和你遇到的问题一样。我发现当你在 Heroku 上使用自定义配置启动 apache 时,它​​开始寻找 index.html 文件,而不是 index.php 文件。

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

为了解决这个问题,我在我的 apache 配置文件中添加了以下行:

DirectoryIndex index.php

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

这会指示 apache 查找 index.php,并修复该问题。

回答by Abu Bakr

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

创建这个 .htaccess 文件并将其放在你的 Laravel 安装文件夹中。

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

solution is Here:enter link description here

解决方案在这里:在此处输入链接描述