Far too often you come across a project on GitHub and you notice that the original developer has left in a config.php
file that contains (in the best case) useless database information or (in the worst case) incredibly important API keys.
When these files aren't accidentally versioned they are often shoved in a .gitignore
file with a sample file attached for developers to amend as they need. One example of a platform that does this is WordPress.
There are some minor improvements to this, such as putting core configuration in an XML file that is buried in some obscure document with plenty of irrelevant configuration.
I've found that there tend to be two good ways of managing environment variables in PHP. The first method involves putting them in a file on your root
folder in a format such as YML and reading these variables as required.
The second way, which I personally prefer, is a method implemented by a library known as dotenv
. Essentially, what happens...