We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Having trouble using .env files with EE

How Do I?

From EE Slack's avatar
From EE Slack
185 posts
2 years ago
From EE Slack's avatar From EE Slack

I’m currently trying to setup ExpressionEngine to run off environment files as per the documentation. I seem to be having trouble getting my config file to pickup the .env.php settings on my install.

Anything specific I should do?

       
From EE Slack's avatar
From EE Slack
185 posts
2 years ago
From EE Slack's avatar From EE Slack

Your .env.php file currently needs to be to be in the same directory as your index.php file for the site.

       
David O'Neill's avatar
David O'Neill
3 posts
2 years ago
David O'Neill's avatar David O'Neill

That is not my experince. I have my .env.php at the same level as my system directory. I can then access any value, for example MY_ENV_VALUE=test in my config files by using $_ENV[‘MY_ENV_VALUE’]

What is really cool is that you can inject that into the config object $config[‘custom_value’] = $_ENV[‘MY_ENV_VALUE’]; and then reference that in your custom add on code like this ee()->config->item(‘custom_value’).

This kind of pattern makes multi environment setups a breeze. You can die and dump $_ENV at the top of your config file to ensure you are getting what you expect.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.