簡體   English   中英

Laravel lumen 內部服務器錯誤 500 使用共享主機?

[英]Laravel lumen Internal server error 500 using shared hosting?

我是 Laravel/lumen 的新手。 我制作了一個簡單的入門代碼來使用控制器函數返回響應。 它在我的本地服務器上運行良好,但是當我使用我的共享主機時,控制器功能的路由給出了 500 個內部服務器錯誤。 任何不使用控制器功能的東西都可以工作。 就像是

$router->get('/', function () use ($router) {
    return phpinfo();
});

返回php信息。 使用 IONOS 主機。 不使用任何數據庫連接。 我在 StackOverflow 中嘗試了幾個類似的答案,但無法弄清楚。 域指向項目的公共文件夾。 嘗試使用FTP和ssh安裝。 兩者結果相同。

Internal Server Error 服務器遇到內部錯誤或配置錯誤,無法完成您的請求。

請聯系服務器管理員,告知他們此錯誤發生的時間,以及您在此錯誤之前執行的操作。

服務器錯誤日志中可能提供有關此錯誤的更多信息。

此外,在嘗試使用 ErrorDocument 處理請求時遇到 500 Internal Server Error 錯誤。

存儲/日志中沒有錯誤信息

控制器代碼... <?php

namespace App\Http\Controllers;

class ExampleController extends Controller
{
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }
    public function profile(){
        return response('hello! Controller Works...');
    }

    //
}

路由器代碼..

<?php

/** @var \Laravel\Lumen\Routing\Router $router */

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It is a breeze. Simply tell Lumen the URIs it should respond to
| and give it the Closure to call when that URI is requested.
|
*/

$router->get('/', function () use ($router) {
    return $router->app->version();
});
$router->get('profile', [
    'as' => 'profile', 'uses' => 'ExampleController@profile'
]);

.htaccess 文件

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

    RewriteEngine On

    # 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>

刪除 .htaccess 將給出未找到的錯誤。 .env 文件

APP_NAME=Lumen
APP_ENV=production
APP_KEY=<my generated key>
APP_DEBUG=false
APP_URL=http://<my domain>
APP_TIMEZONE=UTC

LOG_CHANNEL=stack
LOG_SLACK_WEBHOOK_URL=

CACHE_DRIVER=file
QUEUE_CONNECTION=sync

搜索了一整天后,發現問題出在 .htaccess 文件上。

它應該是RewriteRule ^ /index.php [L]而不是RewriteRule ^ index.php [L]

根據文章,500 個內部服務器錯誤中的大多數都與 .htaccess 文件有關。 所以對於任何新手來說,都有些頭疼。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM