This is the documentation for concrete5 version 5.6 and earlier. View Current Documentation

In case you've ever wondered how to separate the concrete5 configuration files to be specific to the environment they're running on (e.g. development, testing, staging, production), here's one option.

1. Split your configurations file

Originally your configurations file looks somewhat similar to this one on a fresh installation:

<?php
define('DB_SERVER', 'db.host');
define('DB_USERNAME', 'db_user');
define('DB_PASSWORD', 'db_password');
define('DB_DATABASE', 'db_database');
define('PASSWORD_SALT', 'RNAmiBfYC965l3XE0Cwy8eYz185YkaBEMFzvMjCAqzsGl222Ph30668lqeHWj4yw');

Split that environment-specific stuff to their own file. In this example we'll set up the "development" environment and call that "dev".

/config/site.dev.php

<?php
define('DB_SERVER', 'db.host');
define('DB_USERNAME', 'db_user');
define('DB_PASSWORD', 'db_password');
define('DB_DATABASE', 'db_database');

After this your original configuration file should look like this:

/config/site.php

<?php
define('PASSWORD_SALT', 'RNAmiBfYC965l3XE0Cwy8eYz185YkaBEMFzvMjCAqzsGl222Ph30668lqeHWj4yw');

In some situations you might want to have a common password salt for all environments so that users don't need to generate new passwords when moving the database from environment to another one. But in some situations you might want that to be environment-specific, so it's up to you to decide what you want to define specifically to the environment.

The common site.php also comes handy when you need to set common configs for all environments, e.g. date/time formats or whitelabeling configurations.

2. Add the environment config loading line into the site.php

In order to make this method work, you'll need to tell the site.php to load your environment configs. That is done by adding two lines into that file after which it should automatically load your dev-configs. After this addition your config file should look like this:

/config/site.php

<?php
$env = getenv('CONCRETE5_ENV');
require_once dirname(__FILE__).'/site.'.($env === false ? 'dev' : $env).'.php';
// Common configs for all envs
define('PASSWORD_SALT', 'RNAmiBfYC965l3XE0Cwy8eYz185YkaBEMFzvMjCAqzsGl222Ph30668lqeHWj4yw');

So, now you're loading the "dev" configs on all environments by default.

3. Make it load different configs in different environments

After the previous additions, it's rather easy to load different configs in different environments. You only need to add this like into your server's .htaccess file:

.htaccess

SetEnv CONCRETE5_ENV prod

That would set the environment to load its configurations from /config/site.prod.php.

This also requires that you're not storing your .htaccess file in your version control and it's always environment-specific. Other option is to set the environment variable on the server-level when you would not need to worry about the .htaccess file being in your version control.

And of course, this guide is for Apache webservers but it can be applied to other servers as well.

Loading Conversation