kenjis / codeigniter-composer-installer

Installs the offical CodeIgniter 3 with secure folder structure via Composer
MIT License
377 stars 118 forks source link

phpdotenv package integration #16

Closed indrakaw closed 6 years ago

indrakaw commented 7 years ago

Hello there @kenjis, This question may out of repo's issue.

They question: can you integrate vlucas/phpdotenv package in CodeIgniter? if yes, how?

This help a lot because sensitive data can be hidden in config.php.

kenjis commented 7 years ago

@indrakaw You don't need to use it. I don't use it, but I don't write sensitive data in config.php. You can write something like $_SERVER['DB_PASSWORD'] in your production config.php, and set the environment variable for your web server like Apache.

But if you want to use .env, CI4 has a library. https://github.com/bcit-ci/CodeIgniter4/blob/develop/system/Config/DotEnv.php.

You can use it in CI3 easily:

require '/path/to/DotEnv.php';
$env = new DotEnv('/dir'); // where you have `.env`
$env->load();
unset($env);
indrakaw commented 6 years ago

I figured out that config dir has multiple env as folder. What I have to do is add production folder config into .gitignore. As seen on: https://github.com/bcit-ci/codeigniter-website/blob/develop/.gitignore#L1

This may a bit different as expected, but works on ENV too.

Thanks for respond anyway. And sorry for late reply.