I’ve got a “globabVars.php” doc in my own little framework that contains database connection vars etc… I’m thinking would be neat to store outside of the web facing directories to keep it a little more secure. But, then I was thinking, is it really THAT much more secure? I mean, if someone were able to look at my .php files as a whole (without the server processing them) they would be INSIDE my server looking at all my files anyway…
Thoughts?
Moving a config file outside of the web root can prevent this file from getting leaked if you accidentally mis-configure apache. For instance if you remove Apache’s
mod_phpthen all .php files will be treated as text files. I have seen config files moved outside of the web root on production systems for this reason, and it did stop the file from getting leaked! (An admin iced the config during an update, doah!). Although this doesn’t happen very often.If an attacker can control the path of one of these functions:
file_get_contents(),fopen(),readfile()orfgets()then he can read any file on your system. You also have to worry about sql injection. For instance this query under MySQL can be used to read files:select load_file("/etc/passwd").To mitigate this issue, remove
FILEprivileges from your MySQL user account that PHP uses. Also do achmod 500 -R /path/to/web/root, The last 2 zeros keeps any other account from accessing the files. You should also follow it up with achown www-data -R /path/to/web/rootwhere www-data is the user account that php is executed as, you can figure this out by doing a<?php system('whoami');?>.