Sir Mon’s Weblog

Just another weblog

Open Source and Configuration Files…

I’m writing some family tree software which I’m GPL/Open Sourceing. It’s the angkan project in Sourceforge.

While developing, I use a directory for running programs and thus I require real DB credentials. I don’t want to commit these credentials to an open source repository but the size of the project does not warrant a deployment script (yet). Thus, if I were to use the same directory as a repository root for svn, I would be compelled to make the DB credentials generic.

Taking a cue from the way WordPress retrives configuration files, I’ve come up with the following.  I create the config file with the REAL credentials in a directory ABOVE the repository root, while the one in the repository root contains GENERIC credentials. The REAL config file contains just the defines. The config file in the repository root contains code which runs the REAL config file if it exists.

The directory structure will be something like:

+ public_html
+ REAL_ConfigFile
+ project directrory (svn root)
+ GENERIC_ConfigFile

In GENERIC_config.php, prior to setting the db credentials, it first checks to see if a site specific file REAL_config.php exists in the directory above (which will not be committed into the source tree) and if it exists, it “includes” that file. If not, then some default db credentials will be used which can then be cusotmized by those using the software.

For instance a good config file will be something like the following:
if (file_exists( dirname(dirname(__FILE)) . ‘/REAL_config.php’ )) {
require( dirname(dirname(__FILE__)).’/REAL_config.php’ );
} else {
// put default db credentials were
define( ‘HOST’, ‘localhost’ );
define( ‘DB_NAME’, ‘changeme’ );
define( ‘DB_USER’, ‘changeme’ );
define( ‘DB_PASSWORD’, ‘changeme’ );

There may be more elegant ways to do this. But I thought I’d share this particular technique.


December 23, 2009 - Posted by | Uncategorized | , , , , , ,

No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: