PHP Fatal error: Unknown: Failed opening required | public duplicate in index.php link

PHP Fatal error: Unknown: Failed opening required | public duplicate in index.php link

我的项目使用 Zend 3 框架和 php7.2。当我在 Ubuntu 17.04 上构建网络时,该网络无法正常工作。

> php -S 0.0.0.0:8080 -t public public/index.php
[Thu Dec  7 23:25:59 2017] PHP Warning:  Unknown: failed to open stream: No such file or directory in Unknown on line 0
[Thu Dec  7 23:25:59 2017] PHP Fatal error:  Unknown: Failed opening required '/home/isling/workspace/sp/shopping/public/public/index.php' (include_path='.:/usr/share/php') in Unknown on line 0

'.../public/public/index.php' -> public 重复了 ???

-t 参数指定了文档根目录,假定这是指定文件所在的位置。所以你只需要这个:

php -S 0.0.0.0:8080 -t public index.php

我通常把这个放在我的 composer.json:

"scripts": {
    "serve": "php -S 0.0.0.0:8080 -t public/ index.php"
}

然后我可以 composer serve 得到一个开发服务器。

[EDIT 2018-04-27] 此行为在 7.2.3 左右的版本中发生了变化。文件名参数现在似乎是相对于当前目录而不是相对于通过 -t 指定的文档根目录,因此您现在可以使用类似:php -S 0.0.0.0:8080 -t public/ public/index.php

此错误通常在命令中缺少 -tpublic 时抛出。 @Alex 正确地解释了其背后的原因。 首先,导航到您的项目目录,然后从命令行输入它。

php -S localhost:<your port number> -t public

check this link on how to run php built-in web server from command line

我遇到了同样的问题,停用您的防病毒软件一小时。尝试复制粘贴检查 server.php 是否存在于您的文件夹中