PHPackages                             larament/dot-env-editor - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. larament/dot-env-editor

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

larament/dot-env-editor
=======================

Super simple PHP package for updating .env files

v2.0.0(2w ago)121MITPHPPHP &gt;=8.1

Since Dec 19Pushed 2w agoCompare

[ Source](https://github.com/iRaziul/dot-env-editor)[ Packagist](https://packagist.org/packages/larament/dot-env-editor)[ RSS](/packages/larament-dot-env-editor/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (6)Dependencies (1)Versions (7)Used By (0)

dot-env-editor - A dead simple .env editor for PHP
==================================================

[](#dot-env-editor---a-dead-simple-env-editor-for-php)

A robust PHP package designed to simplify the management and manipulation of .env files within your projects. Effortlessly read, write, update, and delete environment variables with ease.

[![Dot-env-editor](https://repository-images.githubusercontent.com/733602796/d2a2796a-569e-4b89-a2da-bac4b14ed849)](https://repository-images.githubusercontent.com/733602796/d2a2796a-569e-4b89-a2da-bac4b14ed849)

Important

If you are looking to load/read environment variables then we highly recommend you [vlucas/phpdotenv](https://github.com/vlucas/phpdotenv).

Features 🔥
----------

[](#features-)

- Effortlessly load and parse .env files
- Get, set, and remove environment variables
- Support for nesting env vars (e.g. DB\_CONNECTION.host)
- Ability to update existing vars or add new ones
- Optionally keep backups of .env files before writing
- Helper methods like `only()` to get subset of variables
- Simple chaining methods for a fluent interface
- Handles formatting values like booleans and strings
- Preserves spacing and comments when writing back to the file
- Compatible with various frameworks and environments, ensuring versatility in usage.
- Built for PHP 8+ with strict typing

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

[](#requirements)

- PHP 8.1 or higher

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

[](#installation)

Install via Composer:

```
composer require larament/dot-env-editor
```

Usage
-----

[](#usage)

```
use Larament\DotEnvEditor\DotEnvEditor;

$envPath = __DIR__ . '/.env';

$editor = new DotEnvEditor(
    $envPath,   // the path to the.env file
    true,       // whether to keep a backup of the .env file before writing
);

// or using the static method
$editor = DotEnvEditor::load($envPath, true);

// set backup directory
$editor->setBackupDir(__DIR__ . '/backups');

// Get all variables
var_dump($editor->all());

// Get a specific variable
echo $editor->get('AUTHOR_NAME');

// Set a variable
$editor->set('AUTHOR_NAME', 'Raziul Islam');

// set multiple variables
$editor->set([
    'AUTHOR_URL' => 'https://raziul.dev',
    'AUTHOR_COUNTRY' => 'Bangladesh',
]);

// Remove a variable
$editor->remove('AUTHOR_URL');

// write back to the file
$editor->write();
```

### You can use chaining methods for a fluent interface 😘

[](#you-can-use-chaining-methods-for-a-fluent-interface-)

```
DotEnvEditor::load($envPath, true)
    ->setBackupDir(__DIR__ . '/backups')
    ->set([
        'AUTHOR_URL' => 'https://raziul.dev',
        'AUTHOR_COUNTRY' => 'Bangladesh',
    ])
    ->remove('AUTHOR_URL')
    ->write();
```

### Dot-Notation &amp; Flat Nesting Support 💡

[](#dot-notation--flat-nesting-support-)

When using dot-notation keys, they are automatically flattened and converted to standard uppercase `snake_case` variables. For example:

- `DB_CONNECTION.host` is converted to `DB_CONNECTION_HOST`
- `app.url` is converted to `APP_URL`

```
$editor->set('DB_CONNECTION.host', '127.0.0.1'); // Writes DB_CONNECTION_HOST=127.0.0.1
```

Usage with Laravel 🔥
--------------------

[](#usage-with-laravel-)

In your `AppServiceProvider`, register DotEnvEditor as a singleton:

```
use Larament\DotEnvEditor\DotEnvEditor;

public function register(): void
{
    $this->app->singleton(DotEnvEditor::class, function () {
        return DotEnvEditor::load(base_path('.env'))
            ->setBackupDir(storage_path('env-backups')) // backup directory
            ->setBackupCount(5); // only keep latest 5 backup
    });
}
```

In your controller, you can inject the `DotEnvEditor` instance and use it to update environment variables:

```
public function update(DotEnvEditor $envEditor)
{
    // Perform form/data validation

    // save the changes
    $envEditor
        ->set([
            'AUTHOR_URL' => 'https://raziul.dev',
            'AUTHOR_COUNTRY' => 'Bangladesh',
        ])
        ->write();
}
```

Do you find this package useful?
--------------------------------

[](#do-you-find-this-package-useful)

If this package has helped to simplify your workflow, consider giving it a ⭐️ on GitHub. Your support encourages further development and improvements! 💖

Support
-------

[](#support)

For support, please open an [issue on GitHb](https://github.com/iRaziul/dot-env-editor/issues) or submit a [pull request](https://github.com/iRaziul/dot-env-editor/pulls).

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE) for more information.

###  Health Score

44

—

FairBetter than 90% of packages

Maintenance96

Actively maintained with recent releases

Popularity9

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~176 days

Recently: every ~221 days

Total

6

Last Release

20d ago

Major Versions

v1.2.2 → v2.0.02026-05-20

### Community

Maintainers

![](https://www.gravatar.com/avatar/c371b774feadb3bfc182f9309ab6aeac6789b993ac63a213fe3aca070f95100d?d=identicon)[Raziul](/maintainers/Raziul)

---

Top Contributors

[![iRaziul](https://avatars.githubusercontent.com/u/51883557?v=4)](https://github.com/iRaziul "iRaziul (11 commits)")

---

Tags

dot-envdot-env-editorphp

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/larament-dot-env-editor/health.svg)

```
[![Health](https://phpackages.com/badges/larament-dot-env-editor/health.svg)](https://phpackages.com/packages/larament-dot-env-editor)
```

###  Alternatives

[social-links/social-links

PHP library to generate share buttons

112348.6k2](/packages/social-links-social-links)[astrotomic/php-conditional-proxy

This package provides a trait and class to allow calling methods based on a condition without breaking the method chain.

31166.8k7](/packages/astrotomic-php-conditional-proxy)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
