Configurable path for .env file - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28) +--- Forum: CodeIgniter 4 Feature Requests (https://forum.codeigniter.com/forumdisplay.php?fid=29) +--- Thread: Configurable path for .env file (/showthread.php?tid=76737) |
Configurable path for .env file - Michal_PB1 - 06-14-2020 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? RE: Configurable path for .env file - sevmusic - 10-29-2021 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(ROOTPATH, ENVFILE); 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'); 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! |