neoph8
neoph8

Reputation: 1

Running PHP using localhost, how does it pick which file to run?

When I type the following into terminal:

$ php -S localhost:8888

It will play the very first php file I have in the current directory, which is my index.php file. But I also have 3 other index files, labeled index1.php, index2.php, and index3.php. Why doesn't it show all of them? How does it pick which one to show when I open localhost:8888 on a web browser?

Upvotes: 0

Views: 714

Answers (1)

aynber
aynber

Reputation: 23010

From the documentation,

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.

Most web servers will look at index.* files in a certain order. Index files with a number in the filename are usually not used for consideration, unless specified in the web server's configuration files.

Upvotes: 1

Related Questions