PHP警告:在未知的0行中没有此文件或目录。

3
我在Linux主机上使用托管,并在Apache2服务器的网站中配置了子域名。我使用Laravel,但默认情况下没有使用Apache2服务。我使用Laravel Artisan命令。 php artisan serve --host 0.0.0.0
它将监听端口8000。因此,为了访问我的网站,我使用http://myipaddress:8000进行访问。
我尝试过“chmod 755或777 public文件夹”,但仍然无法工作。我的Laravel / public文件夹中有.htaccess文件。
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
    Options -MultiViews
</IfModule>

RewriteEngine On

# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]

# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

当我使用8000端口访问我的网站时,出现以下错误:
PHP Warning:  Unknown: failed to open stream: No such file or directory in Unknown on line 0

PHP Fatal error:  Unknown: Failed opening required 'server.php' (include_path='.:/usr/share/php:/usr/share/php/PEAR') in Unknown on line 0

当你执行 $ php artisan serve 命令时,出现了错误?具体是什么错误?请逐步描述! - Set Kyar Wa Lar
当我运行artisan serve时,通常情况下Laravel会在http://0.0.0.0:8000上启动,并且没有错误。但是当我访问我的链接http://myip:8000时,就像上面提到的那样,错误开始产生了。@SetKyarWaLar - FlowCastv
服务器.php文件是否存在? - Jeemusu
@Jeemusu 不好意思,我在 Laravel 目录中找不到它。 - FlowCastv
如果你的server.php一开始就不在那儿,那还有什么不在呢?这是一个旧版的Laravel还是全新安装的?你尝试过对所有目录进行chmod,而不仅仅是public吗?我能给出的唯一建议是检查是否已经安装了PEAR - Jeemusu
显示剩余7条评论
2个回答

7

我知道这是一个老问题,但我遇到了同样的问题,并通过在项目的根目录中添加一个server.php文件来解决。该文件内容如下:

<?php
$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';

5
我遇到了同样的问题,问题的真正原因是:在某个地方,php -S 内置服务器的最后一个参数被更改为一个标志,因此您必须像这样调用它:php -S 127.0.0.1:8000 -t public -f serve.php。在 php 7.0.26 之前,您可以省略 -f
当您调用 php artisan serve 时,会发生以下情况。
如果您想使用 php artisan serve 来提供服务,则需要覆盖 ServeCommand 并在 fire() 方法的最后一行中添加 -f,如下所示:passthru('"'.PHP_BINARY.'"'." -S {$host}:{$port} -t \"{$public}\" -f server.php"); 有关详细信息,请参阅此 stackoverflow 帖子

1
昨天在Ubuntu 16.04上进行安全更新到7.0.28后,我遇到了这个问题,谢谢 :-) - markdwhite
很高兴能帮到你,当我遇到这个问题时,我想把自己的头发都拔光 :D - Sasa Blagojevic

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接