Autodetect environment type and load variables from
.env
togetenv()
automagically.
This is a PHP version of the original Ruby dotenv.
Add this code to your codeigniter index.php before codeigniter core loaded (before this text "* LOAD THE BOOTSTRAP FILE") :
/*
* --------------------------------------------------------------------
* LOAD PHP DOT ENV FILE
* --------------------------------------------------------------------
*
* And away we go...
*
*/
require_once BASEPATH . 'dotenv/autoloader.php';
$dotenv = new Dotenv\Dotenv(__DIR__);
$dotenv->load();
Create .env according your environment by copy file .env.example for database configuration and the other configuration. Example : .env.development, .env.testing, .env.production
Load configuration, in file application/config/database.php change to this configuration
$db['default']['hostname'] = getenv('DB_HOST');
$db['default']['username'] = getenv('DB_USERNAME');
$db['default']['password'] = getenv('DB_PASSWORD');
$db['default']['database'] = getenv('DB_DATABASE');
$db['default']['dbdriver'] = getenv('DB_CONNECTION');
Add ".env" to your .gitignore file
It will be running, thank you
Agung Jati Kusumo – @its_agungjk – agungjk.social@gmail.com
Distributed under the MIT license. See LICENSE
for more information.
https://github.com/agungjk/phpdotenv-for-codeigniter
git checkout -b feature/fooBar
)git commit -am 'Add some fooBar'
)git push origin feature/fooBar
)