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?

- 15
- 4
-
1What URL are you trying to access? – IMSoP May 15 '22 at 20:24
1 Answers
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!

- 674
- 5
- 12
-
I have read this. I just don't quite understand. Does this mean it can only read one directory? – bill chill May 15 '22 at 19:21
-
This is not a full on web server ... it is just a tool to aid application development. I believe you are looking for an Apache or an Nginx webserver on both you can serve a PHP app - if you are looking for development on localhost explore WAMP for windows for example... or the equivalent of your OS... to serve a PHP App you will want at least one of those. – Shlomtzion May 15 '22 at 19:28
-
Does that mean it can only read a single directory? I am sort of stupid so I need it stated directly or else it will bug me forever. – bill chill May 15 '22 at 19:32