An alternative to “hacking” config files

Published on and tagged with cakephp  configuration  subversion

Andy Dawson (aka AD7six) and Felix Geisendörfer (aka the_undefined) presented in the last 24 hours solutions for switching the database configuration based on some criteria. These solutions work fine, but personally I use a different approach.

I try to avoid to add code to configuration files because those files shouldn’t contain any logic. Instead I use Subversion to manage different configurations. In my repository I have at least two folders for each project: a “trunk” folder where the development happens, and a “live” folder which contains the code (and configurations) for the live application. So if I put something online I just export the content of the “live” folder from the repository, and with it the “live” configuration.

4 comments baked

  • Felix Geisendörfer

    Well I can’t argue that that the SVN solution is pretty good, however, I like having this very straight forward method as well since some of the very small projects / code demonstration things I write are not managed via SVN.

  • Kjell Bublitz

    And how do you manage to keep both of your SVN version in synch without overwriting the live config by accident? Some hints would be great. TIA

  • cakebaker

    @Kjell Bublitz: I use a rather pragmatic approach. I just copy the folders I work with (controllers, models, views) to the “live” folder, synchronize the “live” folder with the repository and commit the changes.

  • jzimmerman

    I develop locally on my laptop, have experimented with local svn version control, but since I am the only one working on my projects I usually just gzip my directories for backups.

    I use rsync to deploy code changes to my servers though. I have 2 different database config files. database.php.live, database.php.local.

    My script that runs rsync just moves files around before syncing.

    Here is my script. I execute it from the command line….
    ————————————————————
    #!/bin/bash
    chmod -R 755 *
    cp ./app/config/database.php.live ./app/config/database.php
    rsync -az -e ssh –delete ./ username@example.com:/path/to/public/directory
    cp ./app/config/database.php.local ./app/config/database.php
    ————————————————————

    No logic in my project, just moving files around before and after syncing.

Bake a comment




(for code please use <code>...</code> [no escaping necessary])

© daniel hofstetter. Licensed under a Creative Commons License