One Database file - two servers

16 September, 2006

Show comments

If you have your website on one server for testing/development (like this laptop) and your live site on another, it's quite likely that once in a while your database.php file from one or the other will find itself referring to the wrong database. Over at With Cake a solution was proposed to allow you to switch database sources in the app model, however it might be easier to manage by switching at the source of the 'problem'.

With a modification to your database.php file like so:

The file itself can be moved while syncing the files for your site, without the risk of suddently bringing your live site offline when it can't find the database. Obviously this tip is redundant if you set up your file updates such that the database file is ignored.

This approach can easily be extended to allow switching of database sources for quick testing and the likes, which I might mention in my next post.