Doc #75061 [Opn]: Built-in web server does not look up existing parent dirs for index files

From: Date: Thu, 26 Oct 2017 13:37:26 +0000
Subject: Doc #75061 [Opn]: Built-in web server does not look up existing parent dirs for index files
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-15186@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=75061&edit=1 ID: 75061 Updated by: cmb@php.net Reported by: me at alex dot bio Summary: Built-in web server does not look up existing parent dirs for index files Status: Open Type: Documentation Problem Package: Built-in web server Operating System: Mac OS X 10.12.6 PHP Version: 7.1.8 Block user comment: N Private report: N New Comment: > 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. Previous Comments: ------------------------------------------------------------------------ [2017-08-11 02:37:05] 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-08-10 19:45:18] 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. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=75061&edit=1

« previous php.doc.bugs (#15186) next »