Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
The purpose of it is to have all the environmental variables on one place. So if you move from localhost to distribution, you only have to change one file, it contains all the database names, passwords, domain name, so everything about the environment. It is really beneficial and good practice, makes your life much easier. :)
-
C0D4669024y.env means you can have a DEV vs PROD environment details and not use PROD resources or assets or files or a MySQL database when your building things.
The code base is exactly the same, so you remove the prod checks (for example)
if($env == "prod")
to do the same and rely on the .env file already containing it.
Another way was to add a .env and have the php.ini serve it on every request. -
It's framework specific. But .env is by far the most commonly used convention.
It's a good question and I remember having these when I had just started coding professionally.
Quick summary -
.env will be machine (physical/container) specific
You don't commit your .env file to source control (there are situations where you would, but there always are exceptions)
Example : .env on your machine has a db config for local db and .env on production has a db config for production, the app runtime just picks up the same file everytime.
This is the core idea. There are setups where you have config files like prod.conf, local.conf and the .env file toggles which one to pick (so you could connect to multiple dbs - prod from local - as from the above example) -
mundo0349114yI do mine in either yaml, json or whatever language I am using like .rb or .py
I rather not deal with env variables but that id a preference
Related Rants
I see some of web framework use .env to store configuration file (eg Laravel, CI). Is there any benefits to store configuration file on .env file? Is it consider a good practice?
question
.env
env