Difference between revisions of "Dotenv Usage"
Robert Down (talk | contribs) (Created page with "Starting with version 5.0.1 OpenEMR now supports "Dotenv" files to better enable development. A dotenv file is a file, excluded from version control, that allows each d...") |
Robert Down (talk | contribs) |
||
Line 5: | Line 5: | ||
Currently this only has one effect: ensure the frontend assets are refreshed on every request (It overrides the <code>$v_js_includes</code> variable with a random integer). | Currently this only has one effect: ensure the frontend assets are refreshed on every request (It overrides the <code>$v_js_includes</code> variable with a random integer). | ||
Example .env file | |||
== Example .env file == | |||
<pre>OPENEMR__ENVIRONMENT=dev</pre> | <pre>OPENEMR__ENVIRONMENT=dev</pre> | ||
Future use could include special logging or profiling during development. However, please be wise on where to use this; if you're writing lots of functions that use this feature, you may need to reconsider ''how'' you're writing the functions. | Future use could include special logging or profiling during development. However, please be wise on where to use this; if you're writing lots of functions that use this feature, you may need to reconsider ''how'' you're writing the functions. | ||
<pre>use Dotenv\Dotenv; | == Example usage in code == | ||
$dotenv = new Dotenv( | |||
$dotenv->load(); | <pre>// should only be used in globals.php, is referenced here just as an example | ||
use Dotenv\Dotenv; | |||
if (file_exists("{$webserver_root}/.env") { | |||
$dotenv = new Dotenv($webserver_root); | |||
$dotenv->load(); | |||
} | |||
// From above example | // From above example | ||
Line 23: | Line 28: | ||
// Or, if there's nothing special to happen, just omit the else clause | // Or, if there's nothing special to happen, just omit the else clause | ||
}</pre> | }</pre> | ||
To learn more about Dotenv and some more usage, see the [https://github.com/vlucas/phpdotenv github repository] | To learn more about Dotenv and some more usage, see the [https://github.com/vlucas/phpdotenv github repository] |
Revision as of 22:56, 20 May 2017
Starting with version 5.0.1 OpenEMR now supports "Dotenv" files to better enable development. A dotenv file is a file, excluded from version control, that allows each developer to set specific variables special to the development environment (Or for production testing). An example would be testing interaction with an online cloud service (such as Amazon AWS) where the dev has an access and secret key. Those keys should not be stored in git, code, or a database, they should instead be set on the server level. By utilizing a .env
file, you can simulate that server variable without having to actually go in and mess around under the hood.
In the root directory copy .env.example
to .env
and set the OPENEMR__ENVIRONMENT
variable to dev
Currently this only has one effect: ensure the frontend assets are refreshed on every request (It overrides the $v_js_includes
variable with a random integer).
Example .env file
OPENEMR__ENVIRONMENT=dev
Future use could include special logging or profiling during development. However, please be wise on where to use this; if you're writing lots of functions that use this feature, you may need to reconsider how you're writing the functions.
Example usage in code
// should only be used in globals.php, is referenced here just as an example use Dotenv\Dotenv; if (file_exists("{$webserver_root}/.env") { $dotenv = new Dotenv($webserver_root); $dotenv->load(); } // From above example if (getenv("OPENEMR__ENVIRONMENT") === "dev") { // do something specitifc for a dev site } else { // do something else for any other site (Right now just `prod`) // Or, if there's nothing special to happen, just omit the else clause }
To learn more about Dotenv and some more usage, see the github repository