https://github.com/sergeyakovlev/env-php
A simple library to loads environment variables from “.env” file
https://github.com/sergeyakovlev/env-php
config dotenv env environment php
Last synced: 27 days ago
JSON representation
A simple library to loads environment variables from “.env” file
- Host: GitHub
- URL: https://github.com/sergeyakovlev/env-php
- Owner: sergeyakovlev
- License: mit
- Created: 2022-02-16T07:16:59.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2025-02-28T12:40:16.000Z (over 1 year ago)
- Last Synced: 2025-12-14T17:05:45.648Z (6 months ago)
- Topics: config, dotenv, env, environment, php
- Language: PHP
- Homepage:
- Size: 4.88 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Env
A simple library to loads environment variables from “.env” file.
## Installation
Install via [Composer](https://getcomposer.org/):
```bash
$ composer require sergeyakovlev/env
```
## Usage
### Initialization
```php
use SergeYakovlev\Env\Env;
// If necessary non-default initialization
Env::init('/path/to/project', ['.env.dist', '.env']); // This is the default behavior
```
### Use cases
```php
// The first use case
$dbHostname = Env::var('DB_HOSTNAME');
// The second use case is with the default value
$dbHostname = Env::var('DB_HOSTNAME', 'localhost');
// Check if an environment variable is existed
$dbHostnameIsExists = Env::exists('DB_HOSTNAME');
```
### Example of “.env” file
```ini
# Comment Line
STRING_VAR1=StringValueWithoutSpaces
STRING_VAR2="String value with spaces"
BOOLEAN_VAR1=true
BOOLEAN_VAR2=false
BOOLEAN_VAR3=on
BOOLEAN_VAR4=off
INT_VAR=123
FLOAT_VAR=123.45
```