PHPackages                             markwalet/dotenv-manager - 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. markwalet/dotenv-manager

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

markwalet/dotenv-manager
========================

A Laravel package that helps you edit the .env file programmatically.

v1.8.0(2y ago)97.6k[2 issues](https://github.com/markwalet/dotenv-manager/issues)MITPHPPHP 8.\*

Since Jul 26Pushed 2y ago1 watchersCompare

[ Source](https://github.com/markwalet/dotenv-manager)[ Packagist](https://packagist.org/packages/markwalet/dotenv-manager)[ Fund](https://www.paypal.me/markwalet)[ GitHub Sponsors](https://github.com/markwalet)[ RSS](/packages/markwalet-dotenv-manager/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (10)Dependencies (3)Versions (14)Used By (0)

[![PHP Dotenv manager](https://camo.githubusercontent.com/a8d46c99232c890a294af1eca15994650c3cde16491a63dd454635c71acb2210/68747470733a2f2f62616e6e6572732e6265796f6e64636f2e64652f504850253230446f74656e762532306d616e616765722e706e673f7468656d653d6c69676874267061636b6167654d616e616765723d636f6d706f7365722b72657175697265267061636b6167654e616d653d6d61726b77616c6574253246646f74656e762d6d616e61676572267061747465726e3d63697263756974426f617264267374796c653d7374796c655f31266465736372697074696f6e3d412b5048502b7061636b6167652b746861742b68656c70732b796f752b656469742b7468652b2e656e762b66696c652b70726f6772616d6d61746963616c6c792e266d643d312673686f7757617465726d61726b3d3026666f6e7453697a653d313030707826696d616765733d68747470732533412532462532466c61726176656c2e636f6d253246696d672532466c6f676f6d61726b2e6d696e2e737667267769647468733d323030)](https://github.com/markwalet/dotenv-manager)

[![MIT Licensed](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Latest Stable Version](https://camo.githubusercontent.com/3b5642211bd29e1e4d106c698197c889af3bbdcb8bea13f6951678f95b44efc1/68747470733a2f2f706f7365722e707567782e6f72672f6d61726b77616c65742f646f74656e762d6d616e616765722f762f737461626c65)](https://packagist.org/packages/markwalet/dotenv-manager)[![Build status](https://camo.githubusercontent.com/2748024b7eff079b047910bee3eaaa89cf6e27ba7940d29c665d5e294deff4e0/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6d61726b77616c65742f646f74656e762d6d616e616765722f74657374732e796d6c3f6272616e63683d6d6173746572267374796c653d666c61742d737175617265266c6162656c3d7465737473)](https://github.com/markwalet/dotenv-manager/actions)[![Coverage](https://camo.githubusercontent.com/636f06a6000aa48b6dbeeb10934c87b0bf052794c59013c5acb310eec35a8d3b/68747470733a2f2f636f6465636f762e696f2f67682f6d61726b77616c65742f646f74656e762d6d616e616765722f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/markwalet/dotenv-manager)[![StyleCI](https://camo.githubusercontent.com/87cd0ef39eee4484e6fce3622a7a522494d9e98aa888de27a36503e8734c4d2f/68747470733a2f2f6769746875622e7374796c6563692e696f2f7265706f732f3134323430343435342f736869656c643f6272616e63683d6d6173746572)](https://github.styleci.io/repos/142404454)[![Total Downloads](https://camo.githubusercontent.com/537c95de12a30abdb3e2c38a27f7086e5b673664d1bb7da5ceea34b1cb53b104/68747470733a2f2f706f7365722e707567782e6f72672f6d61726b77616c65742f646f74656e762d6d616e616765722f646f776e6c6f616473)](https://packagist.org/packages/markwalet/dotenv-manager)

A PHP package that helps you edit the .env file programmatically. It works great for building tools like an installation CLI.

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

[](#installation)

You can install this package with composer.

```
composer require markwalet/dotenv-manager
```

This package can be used in every PHP project.

### Laravel

[](#laravel)

The optional `DotenvManagerServiceProvider` makes this package package suitable for Laravel projects.

From Laravel 5.5 and up you don't have to register your service provider anymore because of the package auto-discovery feature.

If you want to register the service provider manually (required for older versions), add the following line to your `config/app.php` file:

```
MarkWalet\DotenvManager\DotenvManagerServiceProvider::class
```

The service provider is also compatible with Laravel Lumen. Just add the following line to your `bootstrap/app.php` file:

```
$app->register(\MarkWalet\DotenvManager\DotenvManagerServiceProvider::class);
```

Usage
-----

[](#usage)

You can get the dotenv manager by resolving it with the app Laravel service container. This will give you a singleton `MarkWalet\DotenvManager\DotenvManager` instance with the right dependencies.

```
$dotenv = app(DotenvManager::class);
```

You can also manually set up an `DotenvManager` class when you are not using Laravel.

Once you have a dotenv instance you can add a new value to the dotenv file:

```
$dotenv->add('FOO', 'Bar')->after('EXISTING_KEY');
```

If you don't specify a location for the new value, the value will be added at the end of the file.

You can also edit dotenv variables:

```
$dotenv->update('EXISTING_KEY', 'updatedValue');
```

This will replace the original value of `EXISTING_KEY` with `updatedValue`.

All values will be automatically formatted to a valid dotenv value.

### Mutating multiple lines

[](#mutating-multiple-lines)

You can use the `mutate()` method when you want to apply multiple changes to the file. The syntax looks a lot like the syntax in Laravel migrations:

```
/**
 * Original content:
 *
 * TEST1=value1
 * TEST2=value2
 * TEST3=value3
 */

$dotenv->mutate(function(DotenvBuilder $builder){
    $builder->add('TEST4', 'escaped value');
    $builder->update('TEST2', 'updated')->after('TEST3');
    $builder->delete('TEST1');
});

/**
 * New content:
 *
 * TEST3=value3
 * TEST2=updated
 * TEST4="escaped value"
 */
```

### Available methods

[](#available-methods)

Below you will find every available method and its underlying class. These methods can be called on the `DotenvManager` class itself and also on the `DotenvBuilder` you get when mutating the dotenv file.

MethodReturns`add(string $key, $value = null)`[Addition](src/Changes/Addition.php)`create(string $key, $value = null)`[Addition](src/Changes/Addition.php)`set(string $key, $value = null)`[Update](src/Changes/Update.php)`update(string $key, $value = null)`[Update](src/Changes/Update.php)`move(string $key)`[Move](src/Changes/Move.php)`delete(string $key)`[Delete](src/Changes/Delete.php)`unset(string $key)`[Delete](src/Changes/Delete.php)Extending the builder
---------------------

[](#extending-the-builder)

You can also extend the builder with your own implementation of the `Change` class. In the example below we are making a class that can increment a value quickly:

```
use MarkWalet\DotenvManager\Changes\Change;

class Increment extends Change
{
    use HasKey;

    function __construct(string $key)
    {
        $this->key = $key;
    }

    public function apply(string $content): string
    {
        $search = '/'.$this->getKey().'=(.*)/';
        preg_match($search, $content, $matches);
        $value = $matches[1];

        $replacement = $this->getKey().'='.($value + 1);

        return preg_replace($search, $replacement, $content);
    }
}

$dotenv->extend('increment', Increment::class);
```

After we extended the builder we can call it through the `DotenvManager` instance:

```
/**
 * Original content:
 *
 * TEST1=value1
 * INCREMENT=56
 */
$dotenv->increment('INCREMENT');

/**
 * New content:
 *
 * TEST1=value1
 * INCREMENT=57
 */
```

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance16

Infrequent updates — may be unmaintained

Popularity24

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity70

Established project with proven stability

 Bus Factor1

Top contributor holds 81.4% 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 ~150 days

Recently: every ~140 days

Total

13

Last Release

1042d ago

PHP version history (4 changes)v1.0.0PHP ^7.0

v1.3.0PHP ^7.2

v1.5.0PHP ~7.4|8.\*

v1.7.0PHP 8.\*

### Community

Maintainers

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

---

Top Contributors

[![markwalet](https://avatars.githubusercontent.com/u/11446771?v=4)](https://github.com/markwalet "markwalet (79 commits)")[![mark-walet](https://avatars.githubusercontent.com/u/75607670?v=4)](https://github.com/mark-walet "mark-walet (18 commits)")

---

Tags

laravelenvironmentdotenv

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/markwalet-dotenv-manager/health.svg)

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

###  Alternatives

[vlucas/phpdotenv

Loads environment variables from `.env` to `getenv()`, `$\_ENV` and `$\_SERVER` automagically.

13.5k602.4M5.4k](/packages/vlucas-phpdotenv)[livewire/volt

An elegantly crafted functional API for Laravel Livewire.

4195.3M84](/packages/livewire-volt)

PHPackages © 2026

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