Skip to content

Instantly share code, notes, and snippets.

@dariodiaz
Forked from antonioribeiro/gist:8429426
Last active August 29, 2015 13:56
Show Gist options
  • Save dariodiaz/8791159 to your computer and use it in GitHub Desktop.
Save dariodiaz/8791159 to your computer and use it in GitHub Desktop.
laravel: environment configuration
Create a .environment file in the root of your application and define your environment and gitignore it:
```
return array(
'LARAVEL_ENV' => 'development',
'POSTGRESQL.HOST' => 'localhost',
'POSTGRESQL.DATABASE_NAME' => 'laraveldatabase',
'POSTGRESQL.DATABASE_USER' => 'laraveluser',
'POSTGRESQL.DATABASE_PASSWORD' => '!Bassw0rT',
);
```
Load it in Laravel right before `$app->detectEnvironment()`:
```
foreach(require __DIR__.'/../.environment' as $key => $value)
{
putenv(sprintf('%s=%s', $key, $value));
}
```
Then just use it everywhere:
```
<?php
return array(
'connections' => array(
'postgresql' => array(
'driver' => 'pgsql',
'host' => getenv('POSTGRESQL.HOST'),
'database' => getenv('POSTGRESQL.DATABASE_NAME'),
'username' => getenv('POSTGRESQL.DATABASE_USER'),
'password' => getenv('POSTGRESQL.DATABASE_PASSWORD'),
'charset' => 'utf8',
'prefix' => '',
'schema' => 'public',
),
),
);
```
Better than use it all in the .htaccess file, IMO.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment