• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
What's the difference between the .env file and App.php?

#1
So I'm trying to learn CI 4 and I have a question. 

In the .env file there are these settings: 

Code:
# app.CSRFProtection  = false
# app.CSRFTokenName  = 'csrf_test_name'
# app.CSRFCookieName  = 'csrf_cookie_name'
# app.CSRFExpire      = 7200
# app.CSRFRegenerate  = true
# app.CSRFExcludeURIs = []


And in Config/App.php there are these:

Code:
    public $CSRFTokenName  = 'csrf_test_name';
    public $CSRFHeaderName = 'X-CSRF-TOKEN';
    public $CSRFCookieName = 'csrf_cookie_name';
    public $CSRFExpire     = 7200;
    public $CSRFRegenerate = true;
    public $CSRFRedirect   = true;

So what's the difference here? Where am I supposed to do my settings? Although I'm pretty sure it's working as it is without uncommenting the settings in the .env file. But why do they exist there?
Reply

#2
So that you can have three servers with different .env files, and you don't need to touch your Config/App.php to change local settings.
Reply

#3
I'm going to rename my Config.php next time I'm on the desktop and see if .env alone is adequate because Config.php works without a .env file Smile

Edit:
I will also try different values in the two files and see which has priority...
Reply

#4
(09-13-2020, 11:09 AM)jreklund Wrote: So that you can have three servers with different .env files, and you don't need to touch your Config/App.php to change local settings.

Thanks for clearly

Learning CI4 from my works, from errors and how to fix bugs in the community

Love CI & Thanks CI Teams

Reply

#5
What will happen if I have different settings in both the App.php file and the .env file. Which one will override the other?
Reply

#6
.env will override your configuration settings.
Reply

#7
Also worth noting: keeping the Config.php file free from passwords and other credentials is good practice, especially when checking-in code in a versioning system.
We use the .env file to set up stuff for development environment. The local environment is setup by the programmer and the CI/CO server inject the .env file for staging and production systems.
Reply

#8
Just so that I understand correctly:
If I fill the "App.php" configuration file LOCAL with the "live" data AND I have an .env file, then the .env file works LOCAL, right?

If I then transfer my project to the server WITHOUT the .env file, will the data from the configuration folder take effect?
Reply

#9
(02-20-2021, 08:03 PM)Codinglander Wrote: Just so that I understand correctly:
If I fill the "App.php" configuration file LOCAL with the "live" data AND I have an .env file, then the .env file works LOCAL, right?

If I then transfer my project to the server WITHOUT the .env file, will the data from the configuration folder take effect?
Settings from the .env file will always overwrite your local settings from app/Config/*.php
If no .env present, the settings from app/Config/*.php will be used.
Reply

#10
Its quick acess to setting
Use to enable env file edit. env
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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