Welcome Guest, Not a member yet? Register   Sign In
One .env File for Development and Production
#1

Hi There,

I have been using CI for years now and now trying my hands on CI4. It has a cool feature where environment variable can be set with .env file.

How can I use one env file for staging and production. I want the ability to change the environment and CI will pick up the relevant variables.

For example:

Production:
prod.aws.user=abc
prod.aws.password=sss

Staging:
staging.aws.user=tyuhd
staging.aws.password=kruryu

When the environment is changed, CI to pick up the respective credentials.

Please advise if this can be achieved in CI4

Regards
Raj
Reply
#2

Environment files are intended to be specific to each environment. Non-secure configurations can be set in the Config files themselves. You could certainly reuse .env or parts of it but the intent is for each environment to have its own.
Reply
#3

Try this:

1. have two files, envdev and envprod
2. use index.php to delete .env file
3. test for local or online platform
4. copy the relevant file to .env.
Reply
#4

Looks like problem is that you don't fully understand how env file and logic works.

You have to repos / systems: staging and prod
Both has the "same" files commited through (or copied over - doesn't matter)

Both systems will use `.env` file - so this means that your own defined variables in those files MUST match (except ones that override system's config variables - that on your own)


Your own example should be like:

Production:
aws.user=abc
aws.password=sss

Staging:
aws.user=tyuhd
aws.password=kruryu
Reply
#5

Thank you everyone for your feedback. It seems things that I want cannot be achieved.
Reply
#6

It’s not that it could not be done, rather I think we are suggesting that you might be hammering a screw. It’s unclear to me what your use case is (whether you need a screwdriver or should find some nails) but if you have some compelling reason to proceed with your requested setup you likely won’t find resources in the framework or User Guide for it.
Reply
#7

(This post was last modified: 04-17-2021, 10:31 AM by John_Betong.)

I set a bool “LOCALHOST” constant which may be useful:
Code:
define("LOCALHOST", "localhost"===$_SERVER["SERVER_ NAME"]):
Reply
#8

Ci4 read. Env before any request 

See  exmple 

#sms. phoneNumber=123


getEnv('sms. PhoneNumber') ;
Reply




Theme © iAndrew 2016 - Forum software by © MyBB