CodeIgniter Forums
What takes priority, System ENV or .env file? - Printable Version

+- CodeIgniter Forums (
+-- Forum: CodeIgniter 4 (
+--- Forum: CodeIgniter 4 Discussion (
+--- Thread: What takes priority, System ENV or .env file? (/thread-69013.html)

What takes priority, System ENV or .env file? - Tripex - 09-27-2017

Currently the .env file does NOT override the system environment.

I agree and think I can argue for system environment variables having the last say (because it is useful when setting up an environment for e.g. testing to have the env vars scoped). I would argue however that they shouldn't, by default at least, be in the .htaccess that is included in the public folder. The problem with this is that is makes it harder to programatically change the environment when running e.g. continuous integration or tests.

I just wanted to be sure that the sys env has last say is intentional?

Relevant function:

Also, while I'm here... is there any place to discuss the development more "live"... like IRC or Slack or?

RE: What takes priority, System ENV or .env file? - kilishan - 09-27-2017

Yes, that was done intentionally, though it does only check "local only" variables which limits the scope a little bit.

What variables are you talking about in the .htaccess? The only one that I recall being in there was the CI_ENVIRONMENT, and that's only there because a number of people were having issues where they didn't have access to other locations to set it. I believe that's old though and could probably be removed, as it's now intended to be in the .env file.

Unfortunately, I am not involved in the more real-time chat options as I'm too slammed with the day job to be able to really help that way.

RE: What takes priority, System ENV or .env file? - ciadmin - 09-27-2017

There is a CI presence on Slack, at
It has a CodeIgniter channel, with signups at
This forum has a bigger audience and much more traffic, and might actually be more "live" than Slack.

RE: What takes priority, System ENV or .env file? - Tripex - 09-28-2017

Thank you for both your responses.

Yes, I agree that CI_ENVIRONMENT env variable should be removed from .htaccess (and no other env vars should be put there, as per design). The documentation around this can be clearer though... I'll see if I can throw together a changeset for you to pull this evening.

I'll stick to the forum then if that is the most "live" medium Smile