Heroku上的Laravel 5.4。禁止您无权访问此服务器上的/

问题描述 投票:2回答:4

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

禁止您无权访问此服务器上的/

我的Procfile:

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 ^(.*)/$ /$1 [L,R=301]

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

    # Handle Authorization Header
    RewriteC

我无法弄清楚我可能会说它来调查'app /'而不是'/'。如果这是导致此错误的原因。

php apache heroku laravel-5.4
4个回答
11
投票

我不知道为什么服务器认为你的root是在/app但是这个错误的发生是因为Heroku应该为你的应用程序提供服务的public/目录的权限。

要解决此问题,只需将以下内容添加到scriptcomposer.json部分即可

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

请注意public/目录的权限更改。

编辑:

当你在它时,检查你的Procfile确保它拼写正确并以大写的P开头。

PS:我知道有些人真的很挑剔,并且会说许可太松懈了。是的,我同意你的看法。你可以把它变成像775这样的东西,让它只是让果汁流动。


2
投票

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


1
投票

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

在Procfile中写下以下行。

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

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

希望这是有帮助的=)


-1
投票

在laravel安装文件夹中创建并放置此.htaccess文件。

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

解决方案在这里:enter link description here

© www.soinside.com 2019 - 2024. All rights reserved.