Separate Configuration for Staging/Production

Hello, I’m trying to create separate configurations (DB, for instance) to be deployed differently to staging/production servers. How is this done exactly? Thanks in advance.

In my experience, there is no one right way of doing this. Since you’ll always have to apply some changes (DB settings, etc.) IMHO the best way is to write a shell script (assuming you’re on Unix) which does the following:

  1. cd to target directory
  2. pull from git
  3. switch appropriate config files

Item 3 assumes that you have (for example, for your DB settings) 2 (or more) config files which the shell script then renames/moves according to your target environment.

Automating this as much as possible is the way to go as otherwise eventually human error will occur.

Hope this helps.

Although it’s a bit of an old thread, here’s my workflow:

  • create a new project
  • add settings.php to the .gitignore
  • copy settings.php to settings-default.php (which goes into git)
  • edit settings for my local (development) environment
  • on the production server I pull from git
  • copy the settings-default.php to settings.php and make the changes necessary for production

That way I won’t have to edit settings.php on every git-pull, and my production passwords are never stored in git.

Plenty of ways to do this. You can even set a setting value like ‘env’ => ‘development’. When env is development, just load another file of settings and merge it with original one, that way you can override all the settings you need to. When env is production, just keep working normally.