Skip to content

Instantly share code, notes, and snippets.

@andrewhl
Created July 7, 2014 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewhl/55b75bc1ccacf656e23e to your computer and use it in GitHub Desktop.
Save andrewhl/55b75bc1ccacf656e23e to your computer and use it in GitHub Desktop.
...
export APP_ENV=production
...
<?php return array (
'DB_HOST' => 'localhost',
'DB_NAME' => 'db_name',
'DB_USERNAME' => 'username',
'DB_PASSWORD' => 'password',
'APP_ENV' => 'local'
);
<?php return array (
'DB_HOST' => 'localhost',
'DB_NAME' => 'production_db_name',
'DB_USERNAME' => 'production_username',
'DB_PASSWORD' => 'production_password',
'APP_ENV' => 'production'
);
# config/database.php
...
'connections' => array(
'sqlite' => array(
'driver' => 'sqlite',
'database' => __DIR__.'/../database/production.sqlite',
'prefix' => '',
),
'pgsql' => array(
'driver' => 'pgsql',
'host' => $_ENV['DB_HOST'],
'database' => $_ENV['DB_NAME'],
'username' => $_ENV['DB_USERNAME'],
'password' => $_ENV['DB_PASSWORD'],
'charset' => 'utf8',
'prefix' => '',
'schema' => 'public',
),
),
...
# is actually: config/production/database.php
...
'connections' => array(
'sqlite' => array(
'driver' => 'sqlite',
'database' => __DIR__.'/../database/production.sqlite',
'prefix' => '',
),
'pgsql' => array(
'driver' => 'pgsql',
'host' => $_ENV['DB_HOST'],
'database' => $_ENV['DB_NAME'],
'username' => $_ENV['DB_USERNAME'],
'password' => $_ENV['DB_PASSWORD'],
'charset' => 'utf8',
'prefix' => '',
'schema' => 'public',
),
),
...
ErrorException
Undefined index: DB_HOST
# bootstrap/start.php
...
$env = $app->detectEnvironment(function() {
return getenv('APP_ENV') ?: 'local';
});
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment