PHPackages                             redot/dotenv-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. redot/dotenv-editor

ActiveLibrary

redot/dotenv-editor
===================

Loads and edits .env files

v1.0.0(2y ago)25MITPHPPHP ^8.1

Since Jul 6Pushed 2y agoCompare

[ Source](https://github.com/redot-src/php-dotenv-editor)[ Packagist](https://packagist.org/packages/redot/dotenv-editor)[ RSS](/packages/redot-dotenv-editor/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (3)Versions (2)Used By (0)

PHP `.env` Editor
=================

[](#php-env-editor)

`redot/dotenv-editor` is a PHP package that provides a simple and convenient way to read, modify, and save environment variables from a `.env` file. It utilizes the `Dotenv` package for parsing the environment file.

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

[](#installation)

You can install the package via Composer:

```
composer require redot/dotenv-editor
```

Usage
-----

[](#usage)

### Creating an Instance

[](#creating-an-instance)

To use the `DotenvEditor` class, create an instance by providing the path to the `.env` file:

```
use Redot\DotenvEditor\DotenvEditor;

$editor = new DotenvEditor('/path/to/.env');
```

Optionally, you can pass a second parameter to enable backup functionality:

```
$editor = new DotenvEditor('/path/to/.env', true);
```

### Getting Environment Variables

[](#getting-environment-variables)

You can retrieve the value of an environment variable by specifying its key:

```
$value = $editor->get('KEY');
```

If the key is not found, you can provide a default value that will be returned instead:

```
$value = $editor->get('KEY', 'default');
```

### Setting Environment Variables

[](#setting-environment-variables)

To set the value of an environment variable, use the `set` method:

```
$editor->set('KEY', 'value');
```

### Saving Changes

[](#saving-changes)

After modifying the environment variables, you need to save the changes back to the `.env` file:

```
$editor->save();
```

This will overwrite the existing file with the updated variables.

### Backup Functionality

[](#backup-functionality)

By default, the backup functionality is disabled. If you want to enable it, pass `true` as the second argument when creating the `DotenvEditor` instance:

```
$editor = new DotenvEditor('/path/to/.env', true);
```

This will create a backup file (`.env.backup`) before saving any changes. The backup file will contain the previous version of the `.env` file.

**Note:** The backup file will be overwritten each time you backup the `.env` file again.

### Example

[](#example)

Here's an example of how you can use the `DotenvEditor` class:

```
use Redot\DotenvEditor\DotenvEditor;
use Redot\DotenvEditor\Exceptions\FileNotFoundException;

try {
    $editor = new DotenvEditor('/path/to/.env');

    $editor->set('APP_ENV', 'production');
    $editor->set('APP_DEBUG', 'false');

    $editor->save();

    echo 'Changes saved successfully.';
} catch (FileNotFoundException $e) {
    echo 'The file could not be found.';
}
```

Testing
-------

[](#testing)

The package includes a test suite that can be run using Pest. run the following command:

```
composer test
```

License
-------

[](#license)

This package is open-source software licensed under the [MIT license](https://opensource.org/licenses/MIT).

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity52

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

Unknown

Total

1

Last Release

1048d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/2fe62c6597d6411df01b9d1c769a0134d825b1462dc7bad4c2524d4150019a5a?d=identicon)[AbdelrhmanSaid](/maintainers/AbdelrhmanSaid)

---

Top Contributors

[![AbdelrhmanSaid](https://avatars.githubusercontent.com/u/70618755?v=4)](https://github.com/AbdelrhmanSaid "AbdelrhmanSaid (5 commits)")

---

Tags

phpenvdotenveditor

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/redot-dotenv-editor/health.svg)

```
[![Health](https://phpackages.com/badges/redot-dotenv-editor/health.svg)](https://phpackages.com/packages/redot-dotenv-editor)
```

PHPackages © 2026

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