Drupal database configuration files - development, testing, and production environments

Drupal database configuration file FAQ: Is there something I can do to quit having to change my Drupal settings.php file every time I go from my Development Environment to Testing and Production?

Yes! One of the things I didn't like about Drupal when I first started working with it was the settings.php file in the sites/default directory. I thought that was THE database configuration file, and you had to keep changing it when you went from Development to Testing to Production.

Stuff like that is fine in the Java world where you use a build tool like Ant to deploy your websites, but with Drupal -- where you often deploy your website with an FTP tool -- it's pretty annoying.

Fortunately the error was on my part. You can specify different settings.php files for your different environments, and here's how you do it.

Separate Drupal settings.php database configuration files

The simple trick is to create different directories under your Drupal "sites" folder. For example, I'm currently developing a new application named "Mini Me", and I have these two environments:

  • A Development environment at http://minime:8888/
  • A Production environment at http://www.example.com/ (this is just a sample URL)

Given these URLs, I can create two Drupal settings.php database configuration files, one for Development, and another for Production. I place my Development database configuration file here:

sites/minime/settings.php

and I place my Production database configuration file here:

sites/www.example.com/settings.php

Note that I don't have a Test environment for this Drupal application -- I'm just writing it for myself -- but if I did, and I had a test URL like test.example.com, I'd place my Drupal database configuration file in a directory like this:

sites/test.example.com/settings.php

As you can see, with this configuration, I can now easily FTP my website to the Production environment and not have to fiddle with the Drupal configuration file each time I send it to the Production server.

The only secrets in any of this are:

  • Your directory needs to match your URL.
  • The database configuration settings in each settings.php file should match your database setup for that environment.

Drupal database configuration files - Summary

I hope this article on how to configure your Drupal database configuration files for your Development, Test, and Production environments has been helpful.