5.7 - Detect Current Environment

Permalink 1 user found helpful
I would like to detect what environment the site is currently running,

IE. local / staging / production

I've noticed there is a function detectEnvironment but not fully work out how to use this correctly.

Can anyone help out.

reason for this is to include the livereload script only if the environment is local

TheRealSean
 
andrew replied on at Permalink Reply
andrew
This thread might be useful to you:

https://www.concrete5.org/community/forums/5-7-discussion/environmen...

Basically you use the application/bootstrap/start.php file to map a local host name to an environment key, and then you create key.file.php in your application/config directory, and don't check that file into your source control.

e.g. if you map "andrew" to "andrew-hostname.whatever", whenever you're running on andrews-hostname.whatever, andrew.database.php will be used for database config, instead of database.php.
dpidan replied on at Permalink Best Answer Reply
dpidan
I was trying to do almost the same thing.
You'll want to first make sure your host names are set up in /application/bootstrap/start.php. You might try PHP gethostname() to find your local host name, or, in your Shell, type: "hostname".

You can add as many hostnames to the arrays as you like - and as many environments as you like. Mine looks something like this:
$app->detectEnvironment(
    array(
        'local' => array(
            'dpidan.local',
            'adi-imac.local'
        ),
        'stage' => array(
            'adistage'
        ),
        'production' => array(
            'myhostingserver.net'
        )
    ));


Finally, the magic that took nearly an hour of digging to find:
$env = Config::getEnvironment();
if ($env == 'local') {
    // add local development tools here
}
JackVanson replied on at Permalink Reply
Hi,

I also have Local, staging and Live.

I have setup the start.php file and all the key. files e.g. local.database.php

On my local when i try to load my site i just get asked to reinstall concrete5 again.

Please can someone help.

Thanks

Jack