Tutorials - Big bits of code to help you do more
Using SilverStripe Environment files for Database ConfigurationTweet
17 February 2010 | | | Supports v2.4, v2.3
Wouldn't it be easy to have a single environment configuration for all your SilverStripe sites without having to reconfigure each one individually? Wouldn't it be great not to have to change environment settings when you push your site from development to live servers? This is easy to achieve using the SilverStripe "ConfigureFromEnv" script.
To set this up, remove your $databaseConfig line from your site _config.php and add:
Then create a new _ss_environment.php file. This can live in your web root, in it's parent or it's parent parent folder. Define the following constants:
/* What kind of environment is this: development, test, or live (ie, production)? */ define('SS_ENVIRONMENT_TYPE', 'dev/test/live'); /* Database connection */ define('SS_DATABASE_SERVER', 'localhost'); define('SS_DATABASE_USERNAME', 'root'); define('SS_DATABASE_PASSWORD', ''); /* Configure a default username and password to access the CMS on all sites in this environment. */ define('SS_DEFAULT_ADMIN_USERNAME', 'username'); define('SS_DEFAULT_ADMIN_PASSWORD', 'password');
Now your _config.php file only needs one setting, a $database parameter that points SilverStripe to the correct database for this server!