How can I make the PHP Built-in Webserver access sub-directories?

664 Views Asked by At

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?

1

There are 1 best solutions below

3
On

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!