How to version control config files pragmatically?

Instead of version-controlling the actual configuration file, you could put a template or defaults file in version control, and a script that would ask for DB information and credential to generate the real config file, which would be excluded from (i.e. ignored by) version control. On checkout, developers could run this script to get a working environment. This script could also be invoked as part of any installation process that your application uses.

Also see my answer to a similar question.


Not sure how your config is implemented, but having hierarchical overides is how I would handle this.

You have a main config that contains common config plus dummy username/password (or leave these out altogether). Each developer then creates a local override.config (or whatever) with their specific username/password. The main config goes under source control, the developer (or machine) local overrides do not.

I've done this in .NET but not PHP so I don't know how easy this would be I'm afraid.


Create a local overrides file that contains the user specific info as PHP variables.

For instance create a file called local_overrides.php which contains the following:

$local_password = 'qUzaEAFK13uK2KHy';

Then in the file that includes your DB password do something like this

$overrides = 'local_overrides.php';

if (file_exists($overrides)) {
   #include_once($overrides);
   $db_password = $local_password;
} else {
   // perform appropriate action: set default? echo error message? log error?    
   $db_password = 'l1m1t3d!'
}

The local overrides file would never has to be seen by source control.