PHPackages                             tofuma/env-exporter - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [CLI &amp; Console](/categories/cli)
4. /
5. tofuma/env-exporter

ActiveLibrary[CLI &amp; Console](/categories/cli)

tofuma/env-exporter
===================

Generate .env files from example templates using system environment variables

v2.1.3(5mo ago)061MITPHPPHP &gt;=7.1

Since Dec 17Pushed 4mo agoCompare

[ Source](https://github.com/tofuma/env-exporter)[ Packagist](https://packagist.org/packages/tofuma/env-exporter)[ RSS](/packages/tofuma-env-exporter/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)DependenciesVersions (3)Used By (0)

ENV Exporter
============

[](#env-exporter)

A simple PHP package to generate `.env` files from example templates using system environment variables.

What does this package do?
--------------------------

[](#what-does-this-package-do)

When you deploy an application, you usually have a `.env.example` file with all the environment variable keys your application needs. The problem is: how do you generate the actual `.env` file with the correct values from your server environment?

This package solves that problem. It reads the keys from your `.env.example` file and creates a new `.env` file containing only the variables that exist in your system environment.

### Why is this useful?

[](#why-is-this-useful)

- **Security**: Only exports variables that your application actually needs (defined in `.env.example`)
- **Automation**: No manual copy-paste of environment variables during deployment
- **Consistency**: Ensures your `.env` file always matches your `.env.example` structure

Requirements
------------

[](#requirements)

- PHP 7.1 or higher

How it works
------------

[](#how-it-works)

1. The package reads your `.env.example` file
2. It extracts all the variable keys (for example: `APP_NAME`, `DB_HOST`, `REDIS_URL`)
3. For each key, it checks if that variable exists in the system environment
4. If the variable exists, it adds the key and value to the output
5. It writes the result to your `.env` file

### Supported formats in .env.example

[](#supported-formats-in-envexample)

The package understands these formats:

```
# Simple key=value
APP_NAME=Laravel

# Empty value
APP_ENV=

# Quoted values
APP_NAME="My App"

# With export prefix
export APP_NAME=Laravel

# Comments are ignored
# This is a comment
; This is also a comment
```

Installation
------------

[](#installation)

```
composer require tofuma/env-exporter
```

Usage
-----

[](#usage)

### Option 1: Using the static method in PHP code

[](#option-1-using-the-static-method-in-php-code)

```
