CodeIgniter Forums
Setting environment in .env - can't get it working - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forum-28.html)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forum-30.html)
+--- Thread: Setting environment in .env - can't get it working (/thread-71756.html)



Setting environment in .env - can't get it working - happyape - 09-19-2018

I downloaded a fresh copy of CI4 from the development branch. The default welcome page displays environment -

Code:
Page rendered in {elapsed_time} seconds. Environment: <?= ENVIRONMENT ?>

I, then, created a copy of "env" to ".env" and only added this line

CI_ENVIRONMENT = production

I still see environment as "development"

I can't find any settings which i can change in config/app.php

What am I doing wrong?


RE: Setting environment in .env - can't get it working - dave friend - 09-19-2018

Could be that CI_ENVIRONMENT was set (by .htaccess?) before the .env is processed. Per the documentation "If the variable exists in the environment already, it will NOT be overwritten."

I've no idea if the documentation is accurate - it is still in development too.


RE: Setting environment in .env - can't get it working - happyape - 09-19-2018

(09-19-2018, 08:56 AM)daveĀ friend Wrote: Could be that CI_ENVIRONMENT was set (by .htaccess?) before the .env is processed. Per the documentation "If the variable exists in the environment already, it will NOT be overwritten."

I've no idea if the documentation is accurate - it is still in development too.

Yes you were right - it was the .htaccess indeed. Thanks for your help.


RE: Setting environment in .env - can't get it working - sv3tli0 - 09-20-2018

CI_ENVIRONMENT = development

At latest build it is working fine..


RE: Setting environment in .env - can't get it working - happyape - 09-20-2018

(09-20-2018, 10:53 PM)sv3tli0 Wrote: CI_ENVIRONMENT = development

At latest build it is working fine..

Yes it is working for me too. But if you intend to switch/control environment using .env files, you must disable it first in the .htaccess file.

My issue above was that I didn't realise it was there in the .htaccess so perhaps it needs to be mentioned in the documentation more clearly on this page https://bcit-ci.github.io/CodeIgniter4/general/environments.html