• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Handling environments using .env

#1
I started with an .htaccess that was pretty standard:


Code:
RewriteEngine On
RewriteBase /

RewriteRule ^(system|application|cgi-bin) - [F,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]


I know CI4 comes with its own .htaccess, but they can sometimes be finicky, so I thought I'd test out using a different one.

Per documentation here: https://bcit-ci.github.io/CodeIgniter4/g...s.html#env

Seems like I should be able to add this to my .env:


Code:
CI_ENVIRONMENT = development


and then CodeIgniter should start displaying errors instead of "whoops". This does not work for me. The only way I can change the environment to development is with this line in .htaccess:


Code:
SetEnv CI_ENVIRONMENT development


So, then I noticed that the env file in root directory is not prefixed with a dot. I added the dot, but still no love.

After that I swapped out my .htaccess file for the one provided by CI4, but still not love.

On this page https://bcit-ci.github.io/CodeIgniter4/g...ation.html it seems to indicate that nothing else should need to be done:


Quote:When your application runs, this file will be automatically loaded and the variables will be put into the environment. This will work in any environment.

If it matters, this is a Ubuntu 16.04 / PHP 7.2 server.

What does one do to get the .env file to work? Please point to documentation if available.
Reply

#2
By default you receive .htaccess file inside the public folder which has
Code:
SetEnv CI_ENVIRONMENT development

If you comment it with # then the value from .env will be used.

To be honest I think that it is not logical .env to be after htaccess but as .env is per instance while the .htaccess is usually stored inside the git repo...
Best VPS Hosting : Digital Ocean
Reply

#3
(09-29-2018, 06:55 AM)sv3tli0 Wrote: By default you receive .htaccess file inside the public folder which has
Code:
SetEnv CI_ENVIRONMENT development

If you comment it with # then the value from .env will be used.

To be honest I think that it is not logical .env to be after htaccess but as .env is per instance while the .htaccess is usually stored inside the git repo...

This is what I expect, but is not working.
Reply

#4
(09-29-2018, 07:18 AM)skunkbad Wrote:
(09-29-2018, 06:55 AM)sv3tli0 Wrote: By default you receive .htaccess file inside the public folder which has
Code:
SetEnv CI_ENVIRONMENT development

If you comment it with # then the value from .env will be used.

To be honest I think that it is not logical .env to be after htaccess but as .env is per instance while the .htaccess is usually stored inside the git repo...

This is what I expect, but is not working.


CI_ENVIRONMENT=production 

And at the first page it shows production Smile
Best VPS Hosting : Digital Ocean
Reply

#5
Yes I got confused with the same i.e. I tried to set the CI_ENVIRONMENT in .env file but it didn't work because I didn't realise it was being set in the public/.htaccess. As mentioned above, I simply commented that out and it works fine now. I suppose it should be made clearer in the documentation.
Reply

#6
The only thing that may be wrong at this case is that we have by default Setenv in the .htaccess ..

By default it should be set inside the env file to development .
Best VPS Hosting : Digital Ocean
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.