php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #75061 Built-in web server does not look up existing parent dirs for index files
Submitted: 2017-08-10 19:45 UTC Modified: 2017-10-26 13:37 UTC
From: me at alex dot bio Assigned:
Status: Open Package: Built-in web server
PHP Version: 7.1.8 OS: Mac OS X 10.12.6
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2017-08-10 19:45 UTC] me at alex dot bio
Description:
------------
---
From manual page: http://www.php.net/features.commandline.webserver
---
Documentation states that:

`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.`

In reality index files from parent directories are not loaded and 404 Not Found error is returned.

Looks like the bug is here: https://github.com/php/php-src/blame/master/sapi/cli/php_cli_server.c#L1400
Code returns instead of trying the parent index.[php|html].

Test script:
---------------
Local directory structure:

D www/
F www/index.php
D www/subdir/

Built-in web server is launched like this:
php -S localhost:8888 -t www

Opening http://localhost:8888/dir/ in the browser fails with 404 error and the root index.php is not loaded.

Expected result:
----------------
Documentation states that built-in server should open index.[php|html] in the parent root folder "If a URI request does not specify a file". The expected result is that the root folder's index.php should be loaded instead of 404 error.


Actual result:
--------------
opening http://localhost:8888/dir/ fails with 404 error and the root index.php is not loaded.

opening http://localhost:8888/dir also fails with 404 error and the root index.php is not loaded.

opening http://localhost:8888/notexistingdir works and correctly loads www/index.php.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-08-11 02:37 UTC] requinix@php.net
-Summary: Built-in web server does not look up parent dirs for index files +Summary: Built-in web server does not look up existing parent dirs for index files -Type: Bug +Type: Documentation Problem
 [2017-08-11 02:37 UTC] requinix@php.net
The traversal only happens for portions of the path that do not exist, and continues up until the parent does exist. At that point there needs to be an index file (if the parent is a directory) or else PHP responds with a 404.

Given the file /a/index.html and directories /a/b/c,
- /a/b/c will 404 (/a/b/c exists without index)
- /a/b/x will 404 (/a/b/x not found, /a/b exists without index)
- /a/x/y works (/a/x/y not found, /a/x not found, /a exists with index)

/a/index.html/x/y works for the same reasons.

I think this is a documentation issue: I assume the intent is to match other web servers' behavior and I believe they work the same way (or at least Apache does).
 [2017-10-26 13:37 UTC] cmb@php.net
> Opening http://localhost:8888/dir/ in the browser fails with 404
> error and the root index.php is not loaded.

> The traversal only happens for portions of the path that do not
> exist, […]

In the OP's given scenario, /dir/ does not exist, so this does not
appear to be a documentation issue, solely.  I cannot, however,
reproduce the reported behavior on Windows.

> I assume the intent is to match other web servers' behavior and
> I believe they work the same way (or at least Apache does).

AFAIK, out-of-the-box Apache does not work this way.  There has to
be an appropriate RewriteRule to inject index.php into the
requested URI.  Everything after the injected index.php is then
regarded as PATH_INFO.
 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC