简体   繁体   English

Laravel lumen 内部服务器错误 500 使用共享主机?

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

I am new to Laravel/lumen.我是 Laravel/lumen 的新手。 I made a simple starter code to return a response using a controller function.我制作了一个简单的入门代码来使用控制器函数返回响应。 It works fine on my local server but when I use my shared hosting, the route to the controller function gives 500 internal server error.它在我的本地服务器上运行良好,但是当我使用我的共享主机时,控制器功能的路由给出了 500 个内部服务器错误。 Anything not using controller functions works.任何不使用控制器功能的东西都可以工作。 Something like就像是

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

returns the php info.返回php信息。 Using IONOS hosting.使用 IONOS 主机。 Not using any database connection.不使用任何数据库连接。 I have tried several similar answers in StackOverflow, but couldn't figure out.我在 StackOverflow 中尝试了几个类似的答案,但无法弄清楚。 The domain points to the public folder of the project.域指向项目的公共文件夹。 Tried using FTP and ssh installation.尝试使用FTP和ssh安装。 Both the same result.两者结果相同。

Internal Server Error The server encountered an internal error or misconfiguration and was unable to complete your request. Internal Server Error 服务器遇到内部错误或配置错误,无法完成您的请求。

Please contact the server administrator at 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.此外,在尝试使用 ErrorDocument 处理请求时遇到 500 Internal Server Error 错误。

There is no error info in the storage/logs存储/日志中没有错误信息

Controller code... <?php控制器代码... <?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...');
    }

    //
}

Router code..路由器代码..

<?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 file .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>

Removing the .htaccess will give a not found error.删除 .htaccess 将给出未找到的错误。 .env file .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

After searching a full day, figured out the problem is with the .htaccess file.搜索了一整天后,发现问题出在 .htaccess 文件上。

it should be RewriteRule ^ /index.php [L] instead of RewriteRule ^ index.php [L]它应该是RewriteRule ^ /index.php [L]而不是RewriteRule ^ index.php [L]

According to the articles, most of the 500 internal server errors are related to .htaccess file.根据文章,500 个内部服务器错误中的大多数都与 .htaccess 文件有关。 So for any newbies, it's a bit of a headache.所以对于任何新手来说,都有些头疼。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM