Question: I want to use Laravel Environment for my Database credential, I did this:

inside `bootstrap\start.php` :

> 
> $env = $app->detectEnvironment(array(
> 
> 
> 'local' => array('My\_PC'),
> 
> 
> 'production' => array('server.example.com')
> 
> 
> ));
> 
> 
> 

created `.env.local.php` on same directory where `serve.php` is, and inside this code:

> 
> return array(
> 
> 
> 
> ```
> 'DATABASE_NAME' => 'laravel_db',
> 'DATABASE_USER' => 'root',
> 'DATABASE_PASSWORD' => '1234' 
> 
> ```
> 
> );
> 
> 
> 

and inside `app\config` created a `local\app.php` file containing this code:

> 
> return array(
> 
> 
> 'debug' => true,
> 
> 
> );
> 
> 
> 

and inside the `app\config\database.php` for my secured mysql connection I did:

```
'mysql' => array(
            'driver'    => 'mysql',
            'host'      => 'localhost',
            'database'  => $_ENV['DATABASE_NAME'],
            'username'  => $_ENV['DATABASE_USER'],
            'password'  => $_ENV['DATABASE_PASSWORD'],
            'charset'   => 'utf8',
            'collation' => 'utf8_unicode_ci',
            'prefix'    => '',
        ),

```

but I'm getting an error on the CLI:

`{"error":{"type":"ErrorException","message":"Undefined index: DATABASE_NAME","file":"c:\\xampp\\htdocs\\Larave_project\\app\\config\\database.php","line":58}}`

How to resolve this issue?

Answer: 
The hostname based env detection solution will only work on Unix type system.
It won't work on Windows.
In Laravel 4.2 you can detect environment this way:

```
$env = $app->detectEnvironment(function() {
    if ($_SERVER['SERVER_NAME'] == "127.0.0.1") {
            $domain = $_SERVER['HTTP_HOST'];

            if (strpos($domain, 'localhost') !== FALSE || strpos($domain, "127.0.0.1") !== FALSE) {
                die("Configure your local `hosts` file and go to address: http://{storeName}.local");
            }

        $len = strpos($domain, ".local");

        if ($len !== FALSE) {
            // will load .env.*.php
            $len = strpos($domain, ".local");
            $env = substr($domain, 0, $len);

            return $env;
        }
    }

    // will load .env.php
    return 'production';
});

```

(this is `bootstrap/start.php`)

Then:

1. setup `hosts` file (in your operating system) to redirect `mysuperstore.local` to 127.0.0.1
2. go to URL like `http://mysuperstore.local` which loads `.env.mysuperstore.php` into `$_ENV`.

In configuration files (those placed in `app/config/`) refer to `$_ENV`. To see where $\_ENV does come from take a look into [documentation topic about "Protecting Sensitive Configuration"](http://laravel.com/docs/4.2/configuration#protecting-sensitive-configuration).