如何使PHP内置网络服务器访问子目录?

发布于 2025-01-29 02:00:14 字数 253 浏览 2 评论 0原文

我一直在尝试使PHP内置网络服务器阅读子目录。我的文件结构是网站 - &GT; HTML,CSS,PHP。我使用php -s localhost:8000将网站文件夹设置为根。 PHP内置网络服务器无法读取此目录。浏览器中的错误是404不喜欢该服务器上所请求的资源 /。终端中的错误是[get] / -no这样的文件或目录< / code>。 Web服务器找不到HTML文件夹内部的index.html文件。我在做什么错?

I have been trying to get the php built-in webserver to read sub directories. My file structure is website --> html, css, php. I set the website folder as the root using php -S localhost:8000. The php built-in webserver cannot read past this directory. The error in the browser is 404 not fond The requested resource / was not found on this server. The error in the terminal is [GET] / -No such file or directory. The webserver cannot find the index.html file that is inside of the html folder. What am I doing wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

命硬 2025-02-05 02:00:14

请在您在Stackoverflow上发布之前尝试探索问题...
您的答案是Google单击几下:“ php内置的Web服务器”搜索在Google上将返回以下内容: https://www.php.net/manual/manual/en/features.commandline.webserver.php 作为第一个命中,它在3D段落上非常清楚地指出:

URI请求是从启动PHP的当前工作目录中提供的,除非使用-t选项指定明确的文档根。如果URI请求未指定文件,则返回给定目录中的index.php或index.html。如果两个文件都不存在,则将在父目录中继续进行index.php和index.html的查找,依此类推,直到找到一个文档或已达到文档根为止。如果找到index.php或index.html,则将其返回,并且将$ _server ['path_info']设置为URI的尾随部分。否则将返回404响应代码。

我实际上是在首先提到的警告!

Please try and explore the problem before you post on stackoverflow...
Your answer was a google few clicks away : "php built in web server" search on google will return this : https://www.php.net/manual/en/features.commandline.webserver.php as the first hit which states very clearly on the 3d paragraph that:

URI requests are served from the current working directory where PHP was started, unless the -t option is used to specify an explicit document root. If a URI request does not specify a file, then either index.php or index.html in the given directory are returned. If neither file exists, the lookup for index.php and index.html will be continued in the parent directory and so on until one is found or the document root has been reached. If an index.php or index.html is found, it is returned and $_SERVER['PATH_INFO'] is set to the trailing part of the URI. Otherwise a 404 response code is returned.

I would actually refer to the warning at the top first!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文