php - dotenv requires .env file on production -


i'm using dotenv php manage environment settings (not lavarel tagged because lavarel uses dotenv)

i have excluded .env code base , have added .env.example other collaborators

on github page of dotenv:

phpdotenv made development environments, , should not used in production. in production, actual environment variables should set there no overhead of loading .env file on each request. can achieved via automated deployment process tools vagrant, chef, or puppet, or can set manually cloud hosts pagodabox , heroku.

the thing don't understand following exception:

php fatal error: uncaught exception 'invalidargumentexception' message 'dotenv: environment file .env not found or not readable.

this contradicts documentation says "the actual environment variables should set there no overhead of loading .env file on each request."

so question if there's reason why dotenv throws exception and/or missing something? first of behavior different compared other dotenv libraries (ruby)

i can work around this, not nice solution:

if(getenv('application_env') !== 'production') { /* or staging */     $dotenv = new dotenv\dotenv(__dir__);     $dotenv->load(); } 

nicest solution in opinion, think dotenv should handle this.

$dotenv = new dotenv\dotenv(__dir__); //check if file exists same way dotenv //see classes dotenv\dotenv , dotenv\loader //$filepath = $dotenv->getfilepath(__dir__);  //this method protected extract code method (see below)  $filepath = rtrim(__dir__, directory_separator).directory_separator . '.env'; //both calls cached (almost) no performance loss if(is_file($filepath) && is_readable($filepath)) {     $dotenv->load(); } 

dotenv built around idea, used in development environments only. thus, expects .env file present.

the solution didn't recommended way use dotenv. , seems, won't change in near future. related discussion in project's issue tracker: https://github.com/vlucas/phpdotenv/issues/63#issuecomment-74561880

note, mark offers there approach production/staging environments, skips file loading, not validation

$dotenv = new dotenv\dotenv(); if(getenv('app_env') === 'development') {     $dotenv->load(__dir__); } $dotenv->required('other_var'); 

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -