The responsibility of the web server is to take a PHP script and pass it to the PHP interpreter, which sends the HTML (or other) output back to the web server.
An incorrectly configured web server may incorrectly process the PHP script and send it to the requesting browser in its raw form, which will allow you to directly access PHP scripts.
Your web host may have a mechanism for listing the contents of the directory, but if it does not provide a loading mechanism to supply a PHP script with text headers (unlike HTML) without passing it to the PHP interpreter, it will be executed as PHP, not served .
To load a raw PHP file, the server will have to do additional work (possibly through another PHP script) that reads the PHP file from disk and sends its contents to the browser using simple text headers.
source share