laravel 刚刚安装了 Lumen 并得到了 NotFoundHttpException

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/36436967/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 13:32:41  来源:igfitidea点击:

Just installed Lumen and got NotFoundHttpException

phplaravellumenlumen-5.2lumen-routing

提问by robertsan

I'm searching for a solution ... it's getting so frustrating. After a fresh installation of Lumen by Laravel, I simply can't access the "/" route. When I try to, it throws an error:

我正在寻找解决方案......它变得如此令人沮丧。在 Laravel 全新安装 Lumen 后,我根本无法访问“/”路由。当我尝试时,它会引发错误:

NotFoundHttpException in RoutesRequests.php line 443:

in RoutesRequests.php line 443
at Application->handleDispatcherResponse(array('0')) in RoutesRequests.php line 380
at Application->Laravel\Lumen\Concerns\{closure}() in RoutesRequests.php line 629
at Application->sendThroughPipeline(array(), object(Closure)) in RoutesRequests.php line 382
at Application->dispatch(null) in RoutesRequests.php line 327
at Application->run() in index.php line 28

回答by robertsan

Got it! ....

知道了!....

The solution is to change in public/index.php at line 28:

解决方法是在 public/index.php 中的第 28 行更改:

$app->run();

to

$app->run($app->make('request'));

No clue why, maybe you know.

不知道为什么,也许你知道。

回答by theQuizProject

The problem was solved by changing the

问题是通过更改解决的

$app->run();

in /public/index.php to

在 /public/index.php 到

$request = Illuminate\Http\Request::capture();
$app->run($request);]

回答by José Maria

I had the same problem today.

我今天遇到了同样的问题。

I was accessing it using the url http://localhost/lumen.api/public/and I think that was the cause of the error.

我使用 url http://localhost/lumen.api/public/访问它 ,我认为这是错误的原因。

To get around it, this is what I did:

为了解决它,这就是我所做的:

First I configured a new VirtualHost entry on Xampp, located in "C:\xampp\apache\conf\extra\httpd-vhosts.conf" in my case:

首先,我在 Xampp 上配置了一个新的 VirtualHost 条目,在我的例子中位于“C:\xampp\apache\conf\extra\httpd-vhosts.conf”:

<VirtualHost *:80>
    DocumentRoot "C:/xampp/htdocs/lumen.api/public"
    ServerName lumen.api
    ServerAlias www.lumen.api
    ErrorLog "logs/lumen.api-error.log"
    CustomLog "logs/lumen.api-access.log" common
    <Directory "C:/xampp/htdocs/lumen.api/public">
        AllowOverride All
        Require all Granted
    </Directory>
</VirtualHost>

and restarted Apache on Xampp.

并在 Xampp 上重新启动 Apache。

Then I edited my hosts file (c:\windows\system32\drivers\etc\hosts) to map a new address to my localhost.

然后我编辑了我的主机文件 (c:\windows\system32\drivers\etc\hosts) 以将一个新地址映射到我的本地主机。

# localhost name resolution is handled within DNS itself.
#   127.0.0.1       localhost
#   ::1             localhost   
    127.0.0.1       lumen.api

I tried again using the new URL http://lumen.apiand the error was gone.

我再次尝试使用新的 URL http://lumen.api并且错误消失了。

回答by llioor

Probably the .htaccess file was deleted or somehow missing from publicfolder. Without it the rewrite URL will not work.

可能 .htaccess 文件已被删除或以某种方式从public文件夹中丢失。没有它,重写 URL 将无法工作。

Check this: https://github.com/laravel/lumen/blob/master/public/.htaccess

检查这个:https: //github.com/laravel/lumen/blob/master/public/.htaccess