PHPackages                             sitopapa/supenv - 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. [Security](/categories/security)
4. /
5. sitopapa/supenv

ActiveLibrary[Security](/categories/security)

sitopapa/supenv
===============

A powerful, zero-dependency PHP Env Manager &amp; Encrypter.

v2.0.0(5mo ago)07MITPHPPHP ^8.1CI passing

Since Nov 24Pushed 5mo agoCompare

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

READMEChangelogDependencies (1)Versions (7)Used By (0)

🔒 Supenv - Secure PHP Env Manager
=================================

[](#-supenv---secure-php-env-manager)

[![Tests](https://github.com/sitopapa/supenv/workflows/Tests/badge.svg)](https://github.com/sitopapa/supenv/actions)[![Code Quality](https://github.com/sitopapa/supenv/workflows/Code%20Quality/badge.svg)](https://github.com/sitopapa/supenv/actions)[![PHP Version](https://camo.githubusercontent.com/7535257ca228724c93658bd52583d4e47a9bab02c356abf6e54c1d575f2151e6/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e312532422d626c75652e737667)](https://php.net)[![License](https://camo.githubusercontent.com/8bb50fd2278f18fc326bf71f6e88ca8f884f72f179d3e555e20ed30157190d0d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d677265656e2e737667)](LICENSE)

**Supenv** is a zero-dependency, production-ready tool to manage, secure, and validate your `.env` files. Use it as a robust **CLI Tool** or integrate it directly into your PHP application as a **Library**.

It uses **Sodium** encryption (industry standard) to keep your secrets safe.

🚀 Features
----------

[](#-features)

- **Zero Dependency:** No external packages required. Lightweight and fast.
- **🔒 Encryption:** Encrypt `.env` to `.env.enc` using Sodium for safe repository storage.
- **🛡️ Type Safety:** Retrieve values as `bool`, `int`, or `string` easily in your code.
- **✅ Validation:** Compare `.env` against `.env.example` to find missing keys (Perfect for CI/CD).
- **🔄 Key Rotation:** Safely rotate your encryption keys without data loss.
- **📦 Auto-Backup:** Automatically creates `.env.bak` before any modification.
- **🙈 Masking:** `list` command masks sensitive data like `API_KEY` or `PASSWORD`.
- **🧪 Fully Tested:** 41 tests with ~95% code coverage.
- **🚀 CI/CD Ready:** Automated testing with GitHub Actions.
- **⚠️ Custom Exceptions:** Type-safe error handling for better debugging.

---

📦 Installation
--------------

[](#-installation)

```
composer require sitopapa/supenv
```

**Requirements:**

- PHP 8.1 or higher
- ext-sodium extension (usually enabled by default)

---

💻 CLI Usage
-----------

[](#-cli-usage)

Supenv comes with a built-in terminal command.

### 1. Direct Usage

[](#1-direct-usage)

```
# Linux / Mac
vendor/bin/supenv list
vendor/bin/supenv help

# Windows
vendor\bin\supenv list
vendor\bin\supenv help
```

### 2. Composer Script (Recommended)

[](#2-composer-script-recommended)

Add this to your `composer.json`:

```
"scripts": {
    "supenv": "supenv"
}
```

Now run:

```
composer supenv list
composer supenv help
```

### CLI Commands

[](#cli-commands)

CommandDescriptionExample**encrypt**Encrypts `.env` → `.env.enc` &amp; generates key`composer supenv encrypt`**decrypt**Decrypts `.env.enc` → `.env``composer supenv decrypt`**list**Lists all variables (masks sensitive data)`composer supenv list`**get**Gets a specific value (unmasked)`composer supenv get DB_PASSWORD`**set**Sets or updates a value`composer supenv set APP_DEBUG true`**unset**Removes a variable`composer supenv unset APP_DEBUG`**rotate**Rotates encryption key safely`composer supenv rotate`**validate**Checks missing keys vs `.env.example``composer supenv validate`**example**Generates `.env.example` from `.env``composer supenv example`---

🔌 Library Usage (PHP)
---------------------

[](#-library-usage-php)

```
use Sitopapa\Supenv\Supenv;

// Initialize
$env = new Supenv(__DIR__ . '/.env');
$env->load();

// --- Reading Data ---
$debug = $env->getBool('APP_DEBUG'); // true/false
$port  = $env->getInt('DB_PORT');    // int 3306
$key   = $env->get('API_KEY');       // string

// --- Writing Data ---
$env->set('DB_HOST', '127.0.0.1');

$env->setMany([
    'APP_ENV' => 'production',
    'CACHE_DRIVER' => 'redis'
]);

// Save changes
$env->save();

// --- Encryption ---
$env->encrypt();          // creates .env.enc
$env->decrypt('.env.enc'); // restores .env

// --- Validation ---
$env->require(['DB_HOST', 'DB_PASSWORD', 'API_KEY']); // Throws ValidationException if missing
```

---

⚠️ Exception Handling
---------------------

[](#️-exception-handling)

Supenv uses custom exceptions for better error handling:

```
use Sitopapa\Supenv\Supenv;
use Sitopapa\Supenv\Exceptions\ValidationException;
use Sitopapa\Supenv\Exceptions\FileNotFoundException;
use Sitopapa\Supenv\Exceptions\DecryptionException;

try {
    $env = new Supenv('.env');
    $env->load();
    $env->require(['DB_HOST', 'DB_PASSWORD']);
} catch (ValidationException $e) {
    // Get missing keys
    $missing = $e->getMissingKeys();
    echo "Missing keys: " . implode(', ', $missing);
} catch (FileNotFoundException $e) {
    echo "File not found: " . $e->getMessage();
} catch (DecryptionException $e) {
    echo "Decryption failed: " . $e->getMessage();
}
```

**Available Exceptions:**

- `SupenvException` - Base exception (all Supenv exceptions extend this)
- `FileNotFoundException` - When a required file is not found
- `EncryptionException` - When encryption fails
- `DecryptionException` - When decryption fails
- `ValidationException` - When validation fails (has `getMissingKeys()` method)
- `SecurityException` - When a security violation is detected

---

🧪 Testing
---------

[](#-testing)

Supenv comes with a comprehensive test suite:

```
# Run all tests
composer test

# Run tests with coverage report
composer test:coverage

# Run specific test
composer test:filter testEncryptionWorks
```

**Test Stats:**

- ✅ 41 tests
- ✅ 92 assertions
- ✅ ~95% code coverage

---

🔒 Security Best Practices
-------------------------

[](#-security-best-practices)

**What to commit:**

- ✅ `.env.enc` (encrypted environment file)
- ✅ `.env.example` (template without values)
- ✅ `.env.key` **ONLY on local development**

**What to NEVER commit:**

- ❌ `.env` (actual environment file with secrets)
- ❌ `.env.bak` (backup file)
- ❌ `.env.key` (encryption key in production)

**Production Deployment:**

1. Commit `.env.enc` to repository
2. Upload `.env.key` to server manually (via SSH, secure file transfer, or secrets manager)
3. Run `supenv decrypt` on server to restore `.env`

### Recommended `.gitignore`

[](#recommended-gitignore)

```
.env
.env.bak
.env.key
```

---

🤝 Contributing
--------------

[](#-contributing)

Contributions are welcome! Please feel free to submit a Pull Request.

**Development:**

```
# Clone the repository
git clone https://github.com/sitopapa/supenv.git
cd supenv

# Install dependencies
composer install

# Run tests
composer test

# Run tests with coverage
composer test:coverage
```

---

🚀 CI/CD
-------

[](#-cicd)

Supenv uses GitHub Actions for automated testing:

- ✅ Tests run on **PHP 8.1, 8.2, 8.3**
- ✅ Cross-platform testing (**Ubuntu**, **Windows**, **macOS**)
- ✅ Automatic code quality checks
- ✅ Composer validation

---

📜 License
---------

[](#-license)

MIT License - see [LICENSE](LICENSE) file for details.

---

🌟 Credits
---------

[](#-credits)

Created and maintained by [Veli GEÇGEL](https://github.com/sitopapa)

---

💡 Support
---------

[](#-support)

If you find this package useful, please consider:

- ⭐ Starring the repository
- 🐛 Reporting bugs
- 💡 Suggesting new features
- 🤝 Contributing to the code

---

**Made with ❤️ in Turkey**

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance70

Regular maintenance activity

Popularity4

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

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 ~0 days

Total

6

Last Release

174d ago

Major Versions

v1.2.0 → v2.0.02025-11-25

PHP version history (2 changes)v1.0.0PHP ^8.0

v2.0.0PHP ^8.1

### Community

Maintainers

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

---

Tags

configurationdotenvencryptionenvphpsecuritysodium

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/sitopapa-supenv/health.svg)

```
[![Health](https://phpackages.com/badges/sitopapa-supenv/health.svg)](https://phpackages.com/packages/sitopapa-supenv)
```

###  Alternatives

[defuse/php-encryption

Secure PHP Encryption Library

3.9k162.4M214](/packages/defuse-php-encryption)[mews/purifier

Laravel 5/6/7/8/9/10 HtmlPurifier Package

2.0k16.7M113](/packages/mews-purifier)[robrichards/xmlseclibs

A PHP library for XML Security

41478.1M118](/packages/robrichards-xmlseclibs)[bjeavons/zxcvbn-php

Realistic password strength estimation PHP library based on Zxcvbn JS

87117.5M63](/packages/bjeavons-zxcvbn-php)[illuminate/encryption

The Illuminate Encryption package.

9229.7M280](/packages/illuminate-encryption)[paragonie/hidden-string

Encapsulate strings in an object to hide them from stack traces

7410.6M39](/packages/paragonie-hidden-string)

PHPackages © 2026

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