【问题标题】:Laravel 5 Server Error 500 Hosting in cpanelLaravel 5 服务器错误 500 在 cpanel 中托管
【发布时间】:2019-04-01 00:55:29
【问题描述】:

我已经将我的 laravel 项目文件夹上传到 cpanel 托管。我在这里遵循了许多示例,但仍然遇到著名的 500 内部错误。这就是我所做的:

我在我的 laravel 项目中分离了公用文件夹并放入我的 public_html 文件夹。我已将我的 laravel 项目的其余部分放入 myapp 文件夹中。

在我的 public_html 文件夹中,我更改了以下几行:

require __DIR__.'/../myapp/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__.'/../myapp/bootstrap/app.php';

这是我的 .env 文件:

APP_NAME=Driveostle
APP_ENV=local
APP_KEY=base64:xxx
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=http://www.driveostle.ma

这是我的 .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
    RewriteCond %{REQUEST_URI} (.+)/$
    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>

这是我的 server.php 文件:

<?php

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

$uri = urldecode(
    parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)
);

// This file allows us to emulate Apache's "mod_rewrite" functionality from the
// built-in PHP web server. This provides a convenient way to test a Laravel
// application without having installed a "real" web server software here.
if ($uri !== '/' && file_exists(__DIR__.'/public'.$uri)) {
    return false;
}

require_once __DIR__.'/public/index.php';

输入域名后,我仍然收到 HTTP ERROR 500。

在这里搜索后,我发现有人要求通过添加以下代码来编辑 .htaccess:

<IfModule mod_rewrite.c>
   RewriteEngine On 
   RewriteRule ^(.*)$ public/$1 [L]
</IfModule>

我得到的错误不一样:

Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator at webmaster@driveostle.ma to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.

Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.

另外,我在 Cpanel 中的 PHP Selector 版本,我选择了 7.1 版本。

在我的 composer.json 文件中:

{
    "name": "laravel/laravel",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "type": "project",
    "require": {
        "php": ">=7.0.0",
        "fideloper/proxy": "~3.3",
        "intervention/image": "^2.4",
        "laravel/framework": "5.5.*",
        "laravel/tinker": "~1.0",
        "mews/purifier": "^2.0"
    },
...

我不知道我的配置中遗漏了什么,这是我第一次托管 laravel 网站,希望我发布的元素能让您了解我遗漏了什么。

如果您需要任何文件内容,我会很乐意发布。

谢谢

【问题讨论】:

  • 您需要检查storage/logs/laravel.log 或主机的错误日志。 500 错误的详细信息将在其中。
  • 先生您好,在storage/logs/laravel.log中,我没有500相关的错误,因为这个文件最后修改的日期是上个月,所以我断定这个文件未受此影响。

标签: laravel .htaccess laravel-5 cpanel web-hosting


【解决方案1】:

我已经多次在共享主机 (cPanel) 上部署我的 Laravel 应用程序,我创建了一个文档,以便我可以帮助我的开发人员伙伴,试试这个

Deploying your Laravel Application to a Shared Hosting (cPanel)

【讨论】:

  • 谢谢你的文件,我做了一模一样的东西,我唯一错过的是filesystems.php,但仍然有500错误。
  • 我可以知道您访问的路线是什么吗?我可以知道你的 routes/web.php 文件的内容吗?
【解决方案2】:

我可能会迟到,但为了将来参考,您可以检查 php 版本并尝试更改它

【讨论】:

    【解决方案3】:

    我也发生了同样的事情,我不得不将以下代码添加到 AppServiceProvider 引导部分:

     public function boot()
        {
            $this->app->bind('path.public', function() {
            return base_path().'/../public_html';
            });
        }
    

    希望对遇到同样问题的人有所帮助。

    【讨论】:

      猜你喜欢
      • 2020-06-28
      • 2016-02-04
      • 1970-01-01
      • 2016-05-24
      • 2018-05-08
      • 2016-05-14
      • 2016-10-02
      • 2015-03-13
      • 2018-08-04
      相关资源
      最近更新 更多