Confusion with .env and config files |
Hello
I am confused with the new addition in CI4, the .env file. Should I use the .env file for the baseURL or I should use the App/Config.php? Which configuration prevails? .env file has Code: app.baseURL = 'http://mydomain.test', but the Config/App.php file also has: Code: public $baseURL = 'http://localhost:8080/'; Also, the .env file has Database settings, but so does the Config/Database.php Confusion goes further: .env file has: Code: encryption.key = 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855' but the Config/Encryption.php has the: Code: public $key = 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'; So, which one should I use? The .env file, or the Config files? Which one is preferred for real-life apps which will be deployed to the clients, but I will have to have them on my localhost as well, for support purposes? Any advice will be deeply appreciated.
The .env file prevail on everything. The way I see it is the app/Config/ directory contains the settings for your dev environment because you don't want your production settings saved in your source control repository. So on your production server you add a .env file that overrides the default settings and is not overwritten when you push an update.
CodeIgniter 4 tutorials (EN/FR) - https://includebeer.com
/*** NO support in private message - Use the forum! ***/ (11-01-2020, 06:48 PM)includebeer Wrote: The .env file prevail on everything. The way I see it is the app/Config/ directory contains the settings for your dev environment because you don't want your production settings saved in your source control repository. So on your production server you add a .env file that overrides the default settings and is not overwritten when you push an update. Thanks for your reply. In such a case, I will then just add the .env on my .gitignore, and I create a .envProduction file, so when I deploy the site I will not replace the production .env file. Using the config files will just confuse me. Once again, thanks for your advice.
(11-02-2020, 02:00 PM)paulbalandan Wrote: .envProduction will not be read. The filename should only be .env Yes, I know that. Client will have file named .env , and I will have 2 files. My .env, and his .env, which will be named .envProduction, so I will know which file is which. No worries. Once again, thank you very much. |
Welcome Guest, Not a member yet? Register Sign In |