php - How can I get Laravel 4 environment variables to work? -


i have created app laravel , have set of environments want run on site always. setup comes start.php file declare environments so:

$env = $app->detectenvironment(array(      'local' => array('mark-macbook.local'),     'development' => array('excelsior.servers.prgn.misp.co.uk'),     'production' => array('excelsior.servers.prgn.misp.co.uk'),  )); 

i create files in root server.php , create files have correct database details each environment in so:

.env.local.php

<?php return array(     'database_host' => 'localhost',     'database_name' => 'borough',     'database_user' => 'root',     'database_password' => 'root',     'unix_socket' => '/applications/mamp/tmp/mysql/mysql.sock' ); 

.env.development.php

<?php return array(     'database_host' => 'localhost',   'database_name' => 'db-name',   'database_user' => 'db-user',   'database_password' => 'pass' ); 

.env.production.php

etc etc

then in database.php file in app/config have setup:

'connections' => array(          'mysql' => array(             'driver'    => 'mysql',             'host'      => $_env['database_host'],             'unix_socket'   => $_env['unix_socket'],             'database'  => $_env['database_name'],             'username'  => $_env['database_user'],             'password'  => $_env['database_password'],             'charset'   => 'utf8',             'collation' => 'utf8_unicode_ci',             'prefix'    => '',         ),      ), 

so setup how know works when run php artisan serve error:

{"error":{"type":"errorexception","message":"undefined index: database_host","file":"\/freelance\/current projects\/borough\/build\/borough-cc\/app\/config\/database.php","line":67}} 

does know why happen , may doing wrong here?

cheers

from memory, haven't used laravel lot, not using correctly.

basically, database access @ configuration keys in kind of global configuration. global config result of combination of config files config folder , environment config.

therefore, need redeclare (or declare) environment specific variables in environment config.

.env.local.php

<?php     return array(         'connections' => array(             'mysql' => array(                 'host'      => 'localhost',                 'unix_socket'   => '/applications/mamp/tmp/mysql/mysql.sock',                 'database'  => 'borough,                 'username'  => 'root,                 'password'  => 'root',             ),         ),     ), ); 

database.php

'connections' => array(     'mysql' => array(         'driver'    => 'mysql',         'charset'   => 'utf8',         'collation' => 'utf8_unicode_ci',         'prefix'    => '',     ), ), 

i'm bit afraid in example not defining same keys in both config... basically, define common config first, redefine whatever need in environment specific files.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -