【问题标题】:Laravel on a shared hosting server returns error 500共享主机服务器上的 Laravel 返回错误 500
【发布时间】:2018-02-26 06:26:03
【问题描述】:

我正在使用共享托管服务器,我安装了我的第一个 Laravel 5.4 应用程序,一切仍然正常。几天前,我在不同的域上安装了另一个 Laravel 5.4 应用程序,但在同一台服务器上,但是当我尝试访问 URL 时,我得到了500 INTERNAL SERVER ERROR。

下面是我的.htaccess代码

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

我也尝试了以下,但同样的错误:

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    ### Add two lines for fix error 500 ###
    Options -Indexes
    php_flag xcache.cacher 0
    #######################################

    # 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
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>

【问题讨论】:

    标签: laravel laravel-5.4


    【解决方案1】:

    您移动了您不应该做的 public_html 文件夹中的所有内容。只有/public 中的文件需要在public_html 中,因此名称为public。 Laravel 文件应放置在公众无法访问的更高目录。

    1. 使用 Softaculous 或使用 composer 通过 SSH 在 /home/username/laravel 中安装 Laravel
    2. 将/home/username/public_html文件夹中的所有内容移动到 /home/username/laravel
    3. 将/home/username/laravel/public中的所有内容移动到/home/username/public_html,并在移动后删除公用文件夹。
    4. 编辑此文件:/home/username/public_html/index.php
    5. 更改为require '/home/username/laravel/vendor/autoload.php';
    6. 更改为$app = require_once '/home/username/laravel/bootstrap/app.php';
    7. 保存此文件并关闭窗口。

    8. 编辑此文件:/home/username/laravel/server.php

    9. 改为:

      if ($uri !== '/' && file_exists('/home/username/public_html'.$uri)) {
          return false;
      }
      
      require_once '/home/username/public_html/index.php';
      

    将username 替换为您的主机用户名。 :)

    【讨论】:

    • 现在它显示了一个不同的错误,当我尝试访问域(forumcover.com)时,它显示了 laravel 框架的完整文件夹结构。当我尝试访问登录路径时(forumcover.com) com/login) 我得到 NOT FOUND “在此服务器上找不到请求的 URL /index.php。此外,在尝试使用 ErrorDocument 处理请求时遇到 404 Not Found 错误。”
    • 请删除,您泄露了您的数据库详细信息!
    • 好的,我会期待您的回复。至于数据库细节我已经改了。
    • 更新了答案,据我所知,如果它有效或者我错过了一些步骤,请告诉我。 :)
    • 执行上述步骤后,我收到“forumcover.com 页面无法正常工作 forumcover.com 目前无法处理此请求。”我将包括“cgi-bin”目录在内的所有文件和文件夹移动到 home/Username/laravel.... 我应该将 cgi-bin 目录留在 home/username/public_html 中吗?
    猜你喜欢
    • 2021-07-29
    • 2021-10-18
    • 1970-01-01
    • 1970-01-01
    • 2021-01-11
    • 2020-12-27
    • 2019-12-08
    • 2018-05-26
    • 1970-01-01
    相关资源
    最近更新 更多