Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Vanilla Forums: how to support multiple configuration options depending on the server/hostname/etc.
<?php
// Detect any specific server environment config setup to apply
// I use a custom variable where you can set like so in Apache VirtualHost or in .htaccess:
// `SetEnv HTTP_SERVER_ENVIRONMENT "staging"
// Default: development
$server_environment = 'development';
if ( ! empty( $_SERVER['HTTP_SERVER_ENVIRONMENT'] ) ) {
$server_environment = $_SERVER['HTTP_SERVER_ENVIRONMENT'];
}
// Load the server environment config, only if a corresponding file exists
$env_config_path = PATH_CONF . '/config-' . $server_environment . '.php';
if ( ! empty( $_SERVER['HTTP_SERVER_ENVIRONMENT'] ) && file_exists( $env_config_path ) ) {
Gdn::Config()->Load( $env_config_path, 'Configuration', TRUE );
}
<?php if (!defined('APPLICATION')) exit();
// Database
$Configuration['Database']['Name'] = 'example_forums_development';
$Configuration['Database']['Host'] = 'localhost';
$Configuration['Database']['User'] = 'root';
$Configuration['Database']['Password'] = 'root';
<?php if (!defined('APPLICATION')) exit();
// Database
$Configuration['Database']['Name'] = 'example_forums';
$Configuration['Database']['Host'] = 'mysql.example_forums.com';
$Configuration['Database']['User'] = 'example_forums';
$Configuration['Database']['Password'] = 'asdf1234!@#$';
<?php if (!defined('APPLICATION')) exit();
// Database
$Configuration['Database']['Name'] = 'example_forums_staging';
$Configuration['Database']['Host'] = 'mysql.example_forums.com';
$Configuration['Database']['User'] = 'example_forums';
$Configuration['Database']['Password'] = 'asdf1234!@#$';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment