Laravel 5.4 在 Heroku 上。 Forbidden 您无权访问/在此服务器上
Laravel 5.4 on Heroku. Forbidden You don't have permission to access / on this server
我已经在 Heroku 上部署了我的 laravel 5.4 应用程序。问题是,我收到此错误消息:
禁止
您无权访问此服务器上的/
我的程序文件:
web: vendor/bin/heroku-php-apache2 public/
查看日志,我发现它一直在尝试 'app/' 而不是 '/'。
我的日志,为方便阅读而删减。
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
我的.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
我不知道我可能在哪里说它是为了调查 'app/' 而不是 '/' .如果这是此错误的原因。
/app
是文件系统上的绝对路径,您的应用程序所在的位置。该错误表明您的 Procfile
实际上并不包含您声称的内容。您可能还没有将其添加并提交给 Git。 Apache 现在正在尝试从 "root" 提供服务,而不是从 public/
子目录提供服务。
我不知道为什么服务器认为您的根目录位于 /app
但此错误的发生是因为 Heroku 应该从中为您的应用程序提供服务的 public/
目录的权限。
要解决此问题,只需将以下内容添加到 composer.json
的 script
部分
"post-install-cmd": [
"php artisan clear-compiled",
"chmod -R 777 public/"
]
请注意 public/
目录的权限更改。
编辑:
当你在写的时候,检查你的 Procfile
确保它拼写正确并且以大写开头 P
。
PS:我知道有些人真的很挑剔,会说权限太松了。是的,我同意你的看法。您可以将其更改为其他内容,例如 775
让我们尽情享受吧。
创建此 .htaccess 文件并将其放入 laravel 安装文件夹。
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/ [L]
</IfModule>
解决方案在这里:enter link description here
在 Laravel 根文件夹中,创建一个名为 Procfile 的文件。
在 Procfile 中写入以下行。
web: vendor/bin/heroku-php-nginx public/
那就重新部署吧!
Src 和更多在这里 https://appdividend.com/2018/04/17/how-to-deploy-laravel-project-on-heroku/
希望这对您有所帮助 =)
我今天遇到了同样的问题,并且找到了一个简单的解决方案。我是 运行 Heroku 上的一个 Laravel 6 应用程序。
在我通过添加 apache 配置文件并使用 Heroku Procfile 中的 -C 选项加载它来设置 HTTPS 重定向后,问题开始了:
web: vendor/bin/heroku-php-apache2 -C apache.conf public/
我收到的错误:
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
所以和你遇到的问题一样。我发现当您在 Heroku 上使用自定义配置启动 apache 时,它开始寻找 index.html 文件,而不是 index.php 文件。
为了解决这个问题,我在我的 apache 配置文件中添加了以下行:
DirectoryIndex index.php
这会指示 apache 寻找 index.php,并解决问题。
即使我按照标记为正确的答案进行操作,此错误仍然存在
(即使我有 运行 heroku run bash
到 ls -l
来查看文件权限)
但我仍然收到此错误,这可能是因为我使用的是不同的本地分支而不是本地主分支,所以我的建议是始终从本地主分支部署,并且当我从另一个分支部署时,我会收到此日志将代码推送到 heroku
NOTICE: No Procfile, using 'web: heroku-php-apache2'
我在 Heroku 上部署我的 Laravel 应用程序时遇到了同样的问题。我试图更改权限 in/of 我的作曲家文件,但这没有帮助。相反,我将其添加到我的 htaccess 文件中:
<IfModule dir_module>
DirectoryIndex index.html index.php
</IfModule>
将此推送到 Heroku 解决了问题。
解决步骤:
将您的项目克隆到您的 PC:
heroku git:clone -a 你的应用程序名称
创建文件名:Procfile
然后保存下面的Procfile代码行: web: vendor/bin/heroku-php-apache2 public/
使用 commed 将您的项目部署回 heroku:
$ git add .
$ git commit -am "make it better"
$ git push heroku master
希望现在没问题运行你的Laravel App!
我使用 echo "web: vendor/bin/heroku-php-apache2 public/" > Procfile
命令创建了 Procfile
,就像 docs 告诉我的那样,但它随后在引号内生成了 Procfile
命令。这就是为什么,即使我按照其他用户的建议修改了我的 composer.json
文件,我仍然收到 403 禁止错误。
伙计们,确保 Procfile
中的命令没有被引号括起来。然后,修改 composer.json
就像建议的批准答案一样并重新部署您的站点。
我删除了 procfile 文件文本周围的引号,它起作用了
如果有人仍然遇到此问题,请确保将 procfile
命名为 Procfile
,大写 P
。
我已经在 Heroku 上部署了我的 laravel 5.4 应用程序。问题是,我收到此错误消息:
禁止 您无权访问此服务器上的/
我的程序文件:
web: vendor/bin/heroku-php-apache2 public/
查看日志,我发现它一直在尝试 'app/' 而不是 '/'。
我的日志,为方便阅读而删减。
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
我的.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
我不知道我可能在哪里说它是为了调查 'app/' 而不是 '/' .如果这是此错误的原因。
/app
是文件系统上的绝对路径,您的应用程序所在的位置。该错误表明您的 Procfile
实际上并不包含您声称的内容。您可能还没有将其添加并提交给 Git。 Apache 现在正在尝试从 "root" 提供服务,而不是从 public/
子目录提供服务。
我不知道为什么服务器认为您的根目录位于 /app
但此错误的发生是因为 Heroku 应该从中为您的应用程序提供服务的 public/
目录的权限。
要解决此问题,只需将以下内容添加到 composer.json
script
部分
"post-install-cmd": [
"php artisan clear-compiled",
"chmod -R 777 public/"
]
请注意 public/
目录的权限更改。
编辑:
当你在写的时候,检查你的 Procfile
确保它拼写正确并且以大写开头 P
。
PS:我知道有些人真的很挑剔,会说权限太松了。是的,我同意你的看法。您可以将其更改为其他内容,例如 775
让我们尽情享受吧。
创建此 .htaccess 文件并将其放入 laravel 安装文件夹。
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/ [L]
</IfModule>
解决方案在这里:enter link description here
在 Laravel 根文件夹中,创建一个名为 Procfile 的文件。
在 Procfile 中写入以下行。
web: vendor/bin/heroku-php-nginx public/
那就重新部署吧! Src 和更多在这里 https://appdividend.com/2018/04/17/how-to-deploy-laravel-project-on-heroku/
希望这对您有所帮助 =)
我今天遇到了同样的问题,并且找到了一个简单的解决方案。我是 运行 Heroku 上的一个 Laravel 6 应用程序。
在我通过添加 apache 配置文件并使用 Heroku Procfile 中的 -C 选项加载它来设置 HTTPS 重定向后,问题开始了:
web: vendor/bin/heroku-php-apache2 -C apache.conf public/
我收到的错误:
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
所以和你遇到的问题一样。我发现当您在 Heroku 上使用自定义配置启动 apache 时,它开始寻找 index.html 文件,而不是 index.php 文件。
为了解决这个问题,我在我的 apache 配置文件中添加了以下行:
DirectoryIndex index.php
这会指示 apache 寻找 index.php,并解决问题。
即使我按照标记为正确的答案进行操作,此错误仍然存在
(即使我有 运行 heroku run bash
到 ls -l
来查看文件权限)
但我仍然收到此错误,这可能是因为我使用的是不同的本地分支而不是本地主分支,所以我的建议是始终从本地主分支部署,并且当我从另一个分支部署时,我会收到此日志将代码推送到 heroku
NOTICE: No Procfile, using 'web: heroku-php-apache2'
我在 Heroku 上部署我的 Laravel 应用程序时遇到了同样的问题。我试图更改权限 in/of 我的作曲家文件,但这没有帮助。相反,我将其添加到我的 htaccess 文件中:
<IfModule dir_module>
DirectoryIndex index.html index.php
</IfModule>
将此推送到 Heroku 解决了问题。
解决步骤:
将您的项目克隆到您的 PC: heroku git:clone -a 你的应用程序名称
创建文件名:Procfile
然后保存下面的Procfile代码行:
web: vendor/bin/heroku-php-apache2 public/
使用 commed 将您的项目部署回 heroku:
$ git add .
$ git commit -am "make it better"
$ git push heroku master
希望现在没问题运行你的Laravel App!
我使用 echo "web: vendor/bin/heroku-php-apache2 public/" > Procfile
命令创建了 Procfile
,就像 docs 告诉我的那样,但它随后在引号内生成了 Procfile
命令。这就是为什么,即使我按照其他用户的建议修改了我的 composer.json
文件,我仍然收到 403 禁止错误。
伙计们,确保 Procfile
中的命令没有被引号括起来。然后,修改 composer.json
就像建议的批准答案一样并重新部署您的站点。
我删除了 procfile 文件文本周围的引号,它起作用了
如果有人仍然遇到此问题,请确保将 procfile
命名为 Procfile
,大写 P
。