As others have said, a misconfigured web server that processes .php files as plain text will happily serve your source code.
Most frameworks (both state and domestic) nowadays store very small PHP code in an area accessible to the Internet. Typically, there is one index.php file in the documentβs root directory that includes and calls code in other files that are completely outside the document root.
Usually you will have something like this:
/path/to/proj/ <-- your project root /path/to/proj/application <-- holds most of your appication code /path/to/proj/lib <-- third-party libraries go here /path/to/proj/public <-- your web server uses this as the document root. /path/to/proj/public/index.php <-- single point of entry into your applicaiton. all requests are routed through here. /path/to/proj/public/images <-- static resources, like images, also live under the docroot.
Rewrite rules are typically used to sort any request through one public index.php file.
With this setup, if your web server had to be configured incorrectly so that it could pass your code, you would be pretty much covered. The only leak will be your index.php file, which is probably a couple of include / require statements and one function / method call. Nothing special.
Look at the standard Zend Framework or Symfony (or any framework, really), the layout of the file, for a clearer image.
timdev
source share