Skip to content

Commit 38a3827

Browse files
committed
Enhance documentation
1 parent abdd3f8 commit 38a3827

File tree

1 file changed

+45
-4
lines changed

1 file changed

+45
-4
lines changed

README.markdown

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
[![Latest Stable Version](https://img.shields.io/packagist/v/josegonzalez/dotenv.svg?style=flat-square)](https://packagist.org/packages/josegonzalez/dotenv)
55

66
# PHP Dotenv
7-
`.env` file parsing for PHP
87

9-
## What is it and why should I use it?
10-
When developing and deploying your applications you are interacting with two different environments. These two places both execute your code but will do so using different credentials, such as database connection credentials, for example. How do you tackle these differing credentials? dotEnv will solve this issue by allowing you to configure your environments and easily switch between them.
8+
A `.env` file parsing and loading library for PHP.
9+
10+
- [What is it and why should I use it?](#what-is-it-and-why-should-i-use-it)
11+
- [Rules to follow](#rules-to-follow)
12+
- [General Security Information](#general-security-information)
1113

1214
## Requirements
1315

@@ -21,7 +23,7 @@ Run `composer require josegonzalez/dotenv:dev-master`
2123

2224
Or add the plugin to your project's `composer.json` - something like this:
2325

24-
```composer
26+
```javascript
2527
{
2628
"require": {
2729
"josegonzalez/dotenv": "dev-master"
@@ -335,6 +337,44 @@ $expect('FOO'); // Returns false if `env` is missing FOO
335337
?>
336338
```
337339

340+
## What is it and why should I use it?
341+
342+
When developing and deploying your applications you are typically interacting with various environments - production and development for instance. These environments both execute your code, but will do so using different credentials. You may also wish to distribute your application to developers without accidentally giving them access to important external services.
343+
344+
Simple examples include authentication keys to your email provider or database connection credentials. You would never want to accidentally send testing emails to all your users, or run a `DROP TABLE` statement against production because you ran your unit tests.
345+
346+
How do you tackle these differing credentials? The `php-dotenv` helps solve this issue by allowing you to configure your environments in a universal fashion, making it easy to safely switch between environments, as well as share those environments with multiple projects/languages.
347+
348+
Need more reasons? Check out the [twelve-factor app docs on configuration](http://12factor.net/config).
349+
350+
## Rules to follow
351+
352+
When using `php-dotenv`, you should strive to follow the following rules:
353+
354+
- Add your `.env` file to a gitignore and use a `.env.default` or `.env.example` to set defaults for your projects. This allows your development team to override defaults in a method that works for their local environment.
355+
- Always set sane development defaults for any credential. If necessary, disable features when those credentials are "invalid".
356+
- Where necessary, add comments to credentials with information as to what they are, how they are used, and how one might procure new ones.
357+
- As `php-dotenv` uses more lax procedures for defining environment variables, ensure your `.env` files are compatible with your shell. A good way to test this is to run the following:
358+
359+
```shell
360+
# source in your .env file
361+
source .env
362+
# check the environment
363+
env
364+
```
365+
- Avoid running `php-dotenv` in production settings, and instead set environment variables in your webserver, process manager, or in bash before running your commands. A simple way to ensure this is to check for the existence of a sentinel environment variable that is *only* set in production:
366+
367+
```php
368+
// APP_NAME isn't set in staging/dev
369+
if (!env('APP_NAME')) {
370+
$loader = new josegonzalez\Dotenv\Loader([
371+
__DIR__ '/.env',
372+
__DIR__ '/.env.default'
373+
]);
374+
$loader->parse()->toEnv();
375+
}
376+
```
377+
338378
## General Security Information
339379
340380
If you configure `php-dotenv` to output configuration in any of the ways listed above and then dump them, they may be available to undesired users. For instance, using a project like [filp/whoops](https://github.com/filp/whoops) in conjunction with `$Loader->toServer()` can result in outputting sensitive data to your users if you leave whoops enabled in production.
@@ -343,6 +383,7 @@ For this reason, `php-dotenv` never populates data to an environment variable by
343383
344384
Many error reporting tools have the option of whitelisting or blacklisting sensitive data, and you should familiarize yourself with said tooling.
345385
386+
346387
## License
347388
348389
The MIT License (MIT)

0 commit comments

Comments
 (0)