Download the PHP package tofuma/env-exporter without Composer
On this page you can find all versions of the php package tofuma/env-exporter. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package env-exporter
ENV Exporter
A simple PHP package to generate .env files from example templates using system environment variables.
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?
- 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
.envfile always matches your.env.examplestructure
Requirements
- PHP 7.1 or higher
How it works
- The package reads your
.env.examplefile - It extracts all the variable keys (for example:
APP_NAME,DB_HOST,REDIS_URL) - For each key, it checks if that variable exists in the system environment
- If the variable exists, it adds the key and value to the output
- It writes the result to your
.envfile
Supported formats in .env.example
The package understands these formats:
Installation
Usage
Option 1: Using the static method in PHP code
Option 2: Using the command line interface (CLI)
Output:
Real World Examples
Example 1: Simple deployment script
Example 2: Docker entrypoint script
In your docker-entrypoint.sh:
In your Dockerfile:
In your docker-compose.yml:
Example 3: Docker with run.sh script
Many projects use a run.sh script to start the application inside a Docker container. This is a common pattern for applications that need to do some setup before starting.
In your run.sh:
In your Dockerfile:
In your docker-compose.yml:
Example 4: Using with Dokploy
Dokploy is a deployment platform that allows you to set environment variables through its web interface. When you add environment variables in Dokploy, they become available as system environment variables in your container.
The problem: Dokploy (and similar platforms) may inject many system variables that you do not need. If you try to export all environment variables, you will get many unnecessary variables.
The solution: This package reads only the keys defined in your .env.example file. This means you only get the variables your application needs.
Step 1: In your Dokploy project, go to the "Environment" tab and add your variables:
Step 2: In your project, make sure you have a .env.example file with all the keys:
Step 3: Create a run.sh script in your project root:
Step 4: In your Dockerfile, use the run.sh script:
The package will create a .env file with only the variables defined in .env.example, using the values from Dokploy environment settings.
Example 5: Kubernetes deployment
In your Kubernetes deployment manifest:
In your container run.sh:
Example 6: GitHub Actions deployment
Example 7: Laravel Forge / Envoyer
In your deployment script:
License
MIT License. See LICENSE for more information.
Author
Created and maintained by tofuma.