My personal preferences are that all that is in the root of the document is a .php file to indicate it is directly executable by the web server, and all that the library is a .inc file stored in a parallel directory to indicate it is NOT directly executable file.
My standard configuration
/home/sites/example.com/html/ - anything here is "safe" to expose if PHP fails and provides raw code
/home/sites/example.com/inc/ - libraries, configuration files with passwords (for example, a database connection class with database credentials), etc. Everything that should not be disclosed, because there is no reason for this.
While you can certainly configure Apache to deny access to .inc files and keep them inside webroot, then you depend on Apache to keep you safe. If PHP can fail in Apache and expose your code, then .inc blocks can also fail and expose your internal instances.
Of course, if Apache coughs up blood across the floor, there is no reason why directory traversal protection cannot fail, and let someone do http://example.com/../inc/seekritpasswords.txt .
At some point, you just need to accept that if something is stored somewhere on the web server, there is a chance that the failure could allow access to the raw data and expose everything. How much time and effort you spend protecting it is up to you.
source share