【问题标题】:Laravel 5.6 HTTP 500 error without any loggingLaravel 5.6 HTTP 500 错误,没有任何日志记录
【发布时间】:2018-11-26 09:51:52
【问题描述】:

我正在尝试在共享主机包上部署 Laravel 5.6 应用程序。此软件包使用 DirectAdmin 和 PHP 7.2。

由于其他应用程序位于public_html 目录的子目录中,我不得不将应用程序也托管在子目录中。

在对在子目录中托管 Laravel 应用程序进行了一些研究后,我的设置如下所示:

- domains
   - example.com
       - public_html
         - laravel
         - otherapp
         - other_site
       - laravel_code

public_html 文件夹中的 laravel 文件夹与 Laravel 应用程序中的每个 public 文件夹具有相同的文件。这意味着文件index.php.htaccess 等...

laravel_code 文件夹目录包含我的应用程序的源代码。我知道我必须将我的index.php 引用到此文件夹。我是这样做的:

<?php

/**
 * Laravel - A PHP Framework For Web Artisans
 *
 * @package  Laravel
 * @author   Taylor Otwell <taylor@laravel.com>
 */

define('LARAVEL_START', microtime(true));

/*
|--------------------------------------------------------------------------
| Register The Auto Loader
|--------------------------------------------------------------------------
|
| Composer provides a convenient, automatically generated class loader for
| our application. We just need to utilize it! We'll simply require it
| into the script here so that we don't have to worry about manual
| loading any of our classes later on. It feels great to relax.
|
*/

require __DIR__ . '/../../laravel_code/vendor/autoload.php';


/*
|--------------------------------------------------------------------------
| Turn On The Lights
|--------------------------------------------------------------------------
|
| We need to illuminate PHP development, so let us turn on the lights.
| This bootstraps the framework and gets it ready for use, then it
| will load up this application so that we can run it and send
| the responses back to the browser and delight our users.
|
*/

$app = require_once __DIR__ . '/../../laravel_code/bootstrap/app.php';

/*
|--------------------------------------------------------------------------
| Run The Application
|--------------------------------------------------------------------------
|
| Once we have the application, we can handle the incoming request
| through the kernel, and send the associated response back to
| the client's browser allowing them to enjoy the creative
| and wonderful application we have prepared for them.
|
*/

$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);

$response = $kernel->handle(
    $request = Illuminate\Http\Request::capture()
);

$response->send();

$kernel->terminate($request, $response);

我的.htaccess 文件如下所示:

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

    RewriteEngine On
    RewriteBase /

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]

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

尝试导航到域时,我只收到 HTTP 500 错误页面,而我的storage/logs文件夹中没有生成任何日志文件。

我已经尝试清除我的缓存并重新缓存我的配置。我也确定我的数据库凭据正常工作。

我的.env 文件如下所示:

APP_NAME=WBS
APP_ENV=local
APP_KEY=base64:knjh2YEuePhEzBblBp5zLJQOQEwaiRBOSkmxz1gcYGw=
APP_DEBUG=true
APP_URL=http://www.example.com/laravel/

LOG_CHANNEL=stack

DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=mydomain
DB_USERNAME=root
DB_PASSWORD=

BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=file
SESSION_LIFETIME=120
QUEUE_DRIVER=sync

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379


PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1

MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"

文件也有适当的权限,我给所有文件755权限进行测试。

什么可能导致此 HTTP 500 错误,我该如何解决?

【问题讨论】:

    标签: php laravel


    【解决方案1】:

    您可以在官方文档中看到它是如何工作的错误处理

    https://laravel.com/docs/5.7/errors

    你可以把 public/index.php 这个代码放在上面并发现问题

    try {
        $app->run();
    } catch(\Exception $e) {
        echo "<pre>";
        echo $e;
        echo "</pre>";
    }
    

    【讨论】:

    • 当来自应用程序的方法在 try/catch 中时,我仍然收到相同的错误 500 页面。
    • 转到您的 PHP 服务器日志,并查找导致 WSOD 的 PHP 错误
    • 在你的路由文件的开头添加一个 die('hello') 命令,然后不断地把它移到你的应用程序中,直到你不再看到 'hello' 消息
    【解决方案2】:

    如果 laravel.log 为空,您可能需要查看 Apache2/Nginx 错误日志。

    您可能仍需要根据您的文件结构更改公共路径(取自here)。将以下内容添加到public/index.php

    $app->bind('path.public', function() { return __DIR__; });

    @Julius 的回答也是部署时常见问题的解决方案。

    【讨论】:

    • 仍然没有成功。我看到的唯一错误是 15 分钟前的错误:[Mon Nov 26 11:03:58.038804 2018] [core:error] [pid 2038141:tid 140217619216128] AH00124: Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace., referer: http://www.example.com/laravel/
    • 那么你的.htaccess文件中有一个无限循环。你改了吗?
    • 现在刷新页面时,错误信息不会出现在 apache 日志中。
    • 马里奥,不幸的是,在那里创建public 文件夹并更改链接时仍然没有成功。还是一样的错误。
    【解决方案3】:

    用于测试,授予存储/文件权限 777。

    chmod -R 777 storage/
    

    【讨论】:

      【解决方案4】:

      我遇到了同样的问题。我使用这个技巧在共享主机上部署 laravel 应用程序。 Reference Lik

      在 Laravel 5.6 中,在你的根目录中创建 .htacess 文件并放置以下代码:

      <IfModule mod_rewrite.c>
      <IfModule mod_negotiation.c>
          Options -MultiViews
      </IfModule>
      
      RewriteEngine On
      
      RewriteCond %{REQUEST_FILENAME} -d [OR]
      RewriteCond %{REQUEST_FILENAME} -f
      RewriteRule ^ ^$1 [N]
      
      RewriteCond %{REQUEST_URI} (\.\w+$) [NC]
      RewriteRule ^(.*)$ public/$1 
      
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteRule ^ server.php
      

      希望对你有帮助。

      【讨论】:

      • 谢谢,我会把这个放在哪里?我在public_html 中的laravel 文件夹没有public/ 文件夹
      • 是在 public_html 中。你不必分离 laravel app 文件夹。您也不必分开公用文件夹。直接从本地部署到服务器即可。
      • 查看link
      【解决方案5】:

      我有同样的问题,在尝试了上面答案中的每一个解决方案后,没有一个有效。然后我尝试在 Tinker 中运行代码,我发现问题是我的代码中存在无限循环。所以 laravel 错误处理程序无法工作或捕获任何错误。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-08-27
        • 2011-09-12
        • 2011-12-21
        • 2016-07-06
        • 2018-08-10
        • 2021-03-30
        • 1970-01-01
        • 2011-06-11
        相关资源
        最近更新 更多