https://github.com/linna/dotenv
Set environment variables from .env file
https://github.com/linna/dotenv
dotenv env php
Last synced: 8 months ago
JSON representation
Set environment variables from .env file
- Host: GitHub
- URL: https://github.com/linna/dotenv
- Owner: linna
- License: mit
- Created: 2018-08-20T14:28:04.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2022-02-20T19:09:11.000Z (over 4 years ago)
- Last Synced: 2025-09-07T06:43:38.487Z (9 months ago)
- Topics: dotenv, env, php
- Language: PHP
- Size: 39.1 KB
- Stars: 3
- Watchers: 2
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
Awesome Lists containing this project
README
[](https://github.com/linna/dotenv/actions/workflows/tests.yml)
[](https://scrutinizer-ci.com/g/linna/dotenv/?branch=master)
[](https://scrutinizer-ci.com/g/linna/dotenv/?branch=master)
[](https://github.styleci.io/repos/145428565)
[](https://github.com/php-pds/skeleton)
[](http://php.net)
# About
This package provide a way to load .env files values as environement variable, it was insiperd by [nodejs counterpart](https://github.com/motdotla/dotenv).
## Requirements
This package require php 7.2
## Installation
With composer:
```
composer require linna/dotenv
```
## Usage
.env.test file as example
```
APP=linna
APP_ENV=production
USER=user.name@linna.tools
FOO=foo
BAR=bar
BAZ=baz
```
php code for get above values
```php
$env = new Linna\DotEnv\DotEnv();
$env->load('.env.test');
$app = $env->get('APP');
$app_env = $env->get('APP_ENV');
//string 'linna' (length=5)
var_dump($app);
//string 'production' (length=10)
var_dump($app_env);
```
environment information in phpinfo()
```php
phpinfo(INFO_ENVIRONMENT);
```

## Notes
DotEnv class use php function [getenv](http://php.net/manual/en/function.getenv.php) and [putenv](http://php.net/manual/en/function.putenv.php) then
key and values will not be loaded in `$_ENV` superglobal.

