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

Hi,
I have a reorganized structure for the application and currently, I can run several domains for one application.
I would need to change the location of the .env file (finally the file for each domain separately), but from what I see it is not possible at the moment.

Does anyone have an idea for this? Idea
Reply
#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




Theme © iAndrew 2016 - Forum software by © MyBB