Welcome Guest, Not a member yet? Register   Sign In
Configurable path for .env file
#2

(This post was last modified: 11-30-2021, 10:53 PM by sevmusic.)

This seems to be working for me.

Keep all of your .env files in the rootpath (along side system and app folders)

Create a duplicate .env file and rename it to whatever suits your needs. (example: .env-dev)

In your /public/index.php add your custom env file name to a constant variable at the top:
PHP Code:
define('ENVFILE''.env-dev'); // constant name and file name are your choice 

In /system/bootstrap.php 
change
PHP Code:
$env = new DotEnv(ROOTPATH); 

to
PHP Code:
$env = new DotEnv(ROOTPATHENVFILE); 

Boom! 

With this change, if you have addon/sub domains, you would create a new env file in the rootpath. (example: .env-new)

In /public/new/index.php add your custom env file name to a constant variable at the top:
PHP Code:
define('ENVFILE''.env-new');

// also change your pathsConfig near line 20
$pathsConfig FCPATH '../../app-new/Config/Paths.php'// or whatever you named your app folder 

Your addon / sub domain should now be looking at its own env file.


Maybe someone can chime in and give me any insight on the downside to doing it this way but it works!
Reply


Messages In This Thread
Configurable path for .env file - by Michal_PB1 - 06-14-2020, 11:43 AM
RE: Configurable path for .env file - by sevmusic - 10-29-2021, 08:03 AM



Theme © iAndrew 2016 - Forum software by © MyBB