Skip to content

Instantly share code, notes, and snippets.

@petehouston
Last active February 19, 2024 10:50
Show Gist options
  • Save petehouston/fdc39a7afa2e872ca6aa to your computer and use it in GitHub Desktop.
Save petehouston/fdc39a7afa2e872ca6aa to your computer and use it in GitHub Desktop.
[Laravel 4.2] The environment dotfile configuration
<?php
//file: /.env.local.php
// return the configuration for the 'local' environment
return array(
'db_host' => '127.0.0.1',
'db_name' => 'DB_NAME', // specify database name
'db_user' => 'DB_USER', // specify database username
'db_pass' => 'DB_PASS', // specify database password
);
# file: /.gitignore
# Laravel #
/bootstrap/compiled.php
/vendor
composer.phar
composer.lock
.env.*.php
.env.php
/bootstrap/environment.php
<?php
//file: /app/config/local/database.php
// return the database configuration
return array(
'connections' => array(
'mysql' => array(
'driver' => 'mysql',
'host' => getenv('db_host'), // equivalent $_ENV['db_host']
'database' => getenv('db_name'),
'username' => getenv('db_user'),
'password' => getenv('db_pass'),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),
);
<?php
//file: /bootstrap/environment.php
/**
* The environment enumeration
* local
* staging
* production
*
*/
return 'local';
<?php
//file: /bootstrap/start.php
...
$env = $app->detectEnvironment(function ()
{
return require __DIR__.'/environment.php'; // load the specified environment
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment