我是Laravel / lumen的新手。我编写了一个简单的入门代码,以使用控制器功能返回响应。它在我的本地服务器上运行良好,但是当我使用共享主机时,到控制器功能的路由会出现500个内部服务器错误。任何不使用控制器功能的方法都可以使用。像
$router->get('/', function () use ($router) {
return phpinfo();
});
返回php信息。 使用IONOS托管。不使用任何数据库连接。我已经在StackOverflow中尝试了几种类似的答案,但无法弄清楚。 域指向项目的公用文件夹。尝试使用FTP和ssh安装。两者结果相同。
内部服务器错误服务器遇到内部错误或 配置错误,无法完成您的请求。
请与服务器管理员联系,以告知他们时间 发生此错误,以及您在此之前执行的操作 错误。
有关此错误的更多信息可能在服务器错误中可用 日志。
此外,在遇到500内部服务器错误错误时 尝试使用ErrorDocument处理请求。
存储/日志中没有错误信息
控制器代码... <?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
答案 0 :(得分:0)
搜索了一整天后,发现问题出在.htaccess文件上。
它应该是RewriteRule ^ /index.php [L]
而不是RewriteRule ^ index.php [L]
根据文章,500个内部服务器错误中的大多数与.htaccess文件有关。因此,对于任何新手来说,都有些头疼。