PHPackages                             encodia/laravel-health-env-vars - 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. [Testing &amp; Quality](/categories/testing)
4. /
5. encodia/laravel-health-env-vars

ActiveLibrary[Testing &amp; Quality](/categories/testing)

encodia/laravel-health-env-vars
===============================

Custom check for Spatie's Laravel Health - Ensure every .env variable you need has been set

1.11.0(2mo ago)20143.5k↓23.8%1[1 PRs](https://github.com/encodia/laravel-health-env-vars/pulls)MITPHPPHP ^8.0CI passing

Since Feb 27Pushed 2mo ago3 watchersCompare

[ Source](https://github.com/encodia/laravel-health-env-vars)[ Packagist](https://packagist.org/packages/encodia/laravel-health-env-vars)[ Docs](https://github.com/encodia/laravel-health-env-vars)[ GitHub Sponsors](https://github.com/encodia)[ RSS](/packages/encodia-laravel-health-env-vars/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (24)Versions (23)Used By (0)

.env vars check for Spatie's Laravel Health
===========================================

[](#env-vars-check-for-spaties-laravel-health)

[![Latest Version on Packagist](https://camo.githubusercontent.com/da371542cdb431f9fdfb391de3ded8cb2d4f3c4cbd52843f11bd27a3e5a11c16/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f656e636f6469612f6c61726176656c2d6865616c74682d656e762d766172732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/encodia/laravel-health-env-vars)[![GitHub Tests Action Status](https://camo.githubusercontent.com/4ca05c34ce441356b9e811217e790e493cb5565863f2bfe84d5a806e3236a842/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f656e636f6469612f6c61726176656c2d6865616c74682d656e762d766172732f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/encodia/laravel-health-env-vars/actions?query=workflow%3Arun-tests+branch%3Amain)[![PHPStan](https://github.com/encodia/laravel-health-env-vars/actions/workflows/phpstan.yml/badge.svg?branch=main)](https://github.com/encodia/laravel-health-env-vars/actions/workflows/phpstan.yml)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/727102cb990e29737ff3c0f49d527de3f0ef4999d2d841b5fe9a813f44495546/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f656e636f6469612f6c61726176656c2d6865616c74682d656e762d766172732f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/encodia/laravel-health-env-vars/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/0e9f765836f213e09d2f74d92a4298120760353257b8aa5881bf0f357cd722d7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f656e636f6469612f6c61726176656c2d6865616c74682d656e762d766172732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/encodia/laravel-health-env-vars)

[Laravel Health](https://github.com/spatie/laravel-health) by [Spatie](https://spatie.be/), in addition to providing some default checks, allows you to create your own.

This package checks if all variables you need have been set in your `.env` file.

Starting from **v1.8.0**, you can also ensure a variable has been set to a certain value.

Some variables are needed in every environment; others only in specific ones. For example, you want to be sure that `BUGSNAG_API_KEY` has been set in your production environment, but you don't need this while developing locally.

> Did anyone say "it works on my machine"?

Who has never lost several minutes before realizing that, let's say in `production`, something is not working because one or more variables have not been valued?

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

[](#requirements)

`encodia/laravel-health-env-vars` requires **PHP 8.0+**, **Laravel 8.0+**.

**PHP 8.1+** is required with **Laravel 10**.

**PHP 8.2+** is required with **Laravel 11** and **Laravel 12**.

**PHP 8.3+** is required with **Laravel 13**.

Version compatibility
---------------------

[](#version-compatibility)

LaravelThis package13.x1.11.012.x1.10.08.x - 11.x1.9.1Installation
------------

[](#installation)

You can install the package via composer:

```
composer require encodia/laravel-health-env-vars
```

Usage
-----

[](#usage)

Register this Check just like the others:

```
// typically, in a service provider

use Spatie\Health\Facades\Health;
use Spatie\Health\Checks\Checks\UsedDiskSpaceCheck;
use Encodia\Health\Checks\EnvVars;

Health::checks([
    // From Spatie's examples
    UsedDiskSpaceCheck::new()
        ->warnWhenUsedSpaceIsAbovePercentage(70)
        ->failWhenUsedSpaceIsAbovePercentage(90),

    // Many other checks...

    /*
     * Check that SOME_API_KEY and MAIL_FROM_ADDRESS variables are
     * set (no matter in which environment)
     */
    EnvVars::new()
        ->requireVars([
            'SOME_API_KEY',
            'MAIL_FROM_ADDRESS',
        ])
]);
```

Need to check only in a specific environment if a variable has been set?

No problem:

```
use Spatie\Health\Facades\Health;
use Encodia\Health\Checks\EnvVars;

Health::checks([
    // ...
    // (other checks)
    // ...

    /*
     * Check that SOME_API_KEY and MAIL_FROM_ADDRESS variables are
     * set (no matter in which environment).
     *
     * Only in staging, ensure EXTENDED_DEBUG_MODE has been set.
     *
     * Additionally, only in production,
     * ensure BUGSNAG_API_KEY has been set.
     */
    EnvVars::new()
        ->requireVars([
            'SOME_API_KEY',
            'MAIL_FROM_ADDRESS',
        ])
        ->requireVarsForEnvironment('staging', [
            'EXTENDED_DEBUG_MODE'
        ])
        ->requireVarsForEnvironment('production', [
            'BUGSNAG_API_KEY'
        ]);
]);
```

It's very likely that you need some variables in multiple environments, but not in all of them.

For example, you need to set `BUGSNAG_API_KEY` only in these environments:

- `qa`
- `production`

but not in `local`, `staging`, `demo` or whatever.

You could chain multiple `requireVarsForEnvironment` calls but, in this case, it's better to use `requireVarsForEnvironments`:

```
use Spatie\Health\Facades\Health;
use Encodia\Health\Checks\EnvVars;

Health::checks([
    // ...
    // (other checks)
    // ...

    /*
     * Check that SOME_API_KEY and MAIL_FROM_ADDRESS variables are
     * set (no matter in which environment).
     *
     * Only in staging, ensure EXTENDED_DEBUG_MODE has been set.
     *
     * Additionally, only in qa and production environments,
     * ensure BUGSNAG_API_KEY has been set.
     */
    EnvVars::new()
        ->requireVars([
            'SOME_API_KEY',
            'MAIL_FROM_ADDRESS',
        ])
        ->requireVarsForEnvironment('staging', [
            'EXTENDED_DEBUG_MODE'
        ])
        ->requireVarsForEnvironments(['qa', 'production'], [
            'BUGSNAG_API_KEY'
        ]);
]);
```

Need to check if a variable has been set to a specific value?

Starting from **v1.8.0**, you can use `requireVarsMatchValues` to perform this check, regardless of the current environment.

If you need to run this check only if the current environment matches the given one(s), you can use `requireVarsForEnvironment` or `requireVarsForEnvironments`.

Examples:

```
use Encodia\Health\Checks\EnvVars;
use Spatie\Health\Facades\Health;

Health::checks([
    EnvVars::new()
        // ... other methods ...
        ->requireVarsMatchValues([
            // Ensure that APP_LOCALE is set to 'en' (no matter which is the current environment)
            'APP_LOCALE' => 'en',
            // Ensure that APP_TIMEZONE is set to 'UTC' (no matter which is the current environment)
            'APP_TIMEZONE' => 'UTC',
        ])
        ->requireVarsMatchValuesForEnvironment('staging', [
            // Only if current environment is 'staging', we don't want to send e-mails to real customers
            'MAIL_MAILER' => 'log',
        ])
        ->requireVarsMatchValuesForEnvironments(['qa', 'production'], [
            // Only if current environment is 'qa' or 'production, we want to log 'info' events or above
            'LOG_LEVEL' => 'info',
            // Only if current environment is 'qa' or 'production, we want to store assets to S3
            'FILESYSTEM_DISK' => 's3',
        ]);
]);
```

⚠️ When checking values, do not store personal data, keys, tokens, etc.!

Caveats
-------

[](#caveats)

During your deployment process, be sure to run EnvVars checks **before**caching your configuration!

Why? After running `php artisan config:cache`, any `env('WHATEVER_NAME')` will return `null`, so your EnvVars checks will fail.

Please check

- [Laravel documentation](https://laravel.com/docs/9.x/configuration#configuration-caching)
- [env() Gotcha in Laravel When Caching Configuration](https://andy-carter.com/blog/env-gotcha-in-laravel-when-caching-configuration)

Important

From version `1.9.0`, when configuration is cached (e.g. via `php artisan config:cache`), these checks are bypassed and they return `OK`.

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Erik D'Ercole](https://github.com/eleftrik)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

###  Health Score

55

—

FairBetter than 98% of packages

Maintenance86

Actively maintained with recent releases

Popularity41

Moderate usage in the ecosystem

Community15

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 61.9% 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 ~81 days

Recently: every ~158 days

Total

19

Last Release

76d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/9489601c40ff678252f4735f7ab07e9ab43233ffc1392048d2b205f75f87131b?d=identicon)[encodia](/maintainers/encodia)

---

Top Contributors

[![eleftrik](https://avatars.githubusercontent.com/u/6959298?v=4)](https://github.com/eleftrik "eleftrik (91 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (29 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (20 commits)")[![encodiaweb](https://avatars.githubusercontent.com/u/7887270?v=4)](https://github.com/encodiaweb "encodiaweb (6 commits)")[![davideprevosto](https://avatars.githubusercontent.com/u/28837345?v=4)](https://github.com/davideprevosto "davideprevosto (1 commits)")

---

Tags

composer-packagehealth-checklaravelspatie-laravel-healthspatielaravelhealthenvironmentenvchecksencodialaravel-health-env-vars

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/encodia-laravel-health-env-vars/health.svg)

```
[![Health](https://phpackages.com/badges/encodia-laravel-health-env-vars/health.svg)](https://phpackages.com/packages/encodia-laravel-health-env-vars)
```

###  Alternatives

[spatie/laravel-activitylog

A very simple activity logger to monitor the users of your website or application

5.8k45.4M309](/packages/spatie-laravel-activitylog)[spatie/laravel-responsecache

Speed up a Laravel application by caching the entire response

2.8k8.2M51](/packages/spatie-laravel-responsecache)[spatie/laravel-health

Monitor the health of a Laravel application

86910.0M83](/packages/spatie-laravel-health)[spatie/laravel-livewire-wizard

Build wizards using Livewire

4061.0M4](/packages/spatie-laravel-livewire-wizard)[spatie/laravel-mail-preview

A mail driver to quickly preview mail

1.3k419.3k5](/packages/spatie-laravel-mail-preview)[spatie/laravel-prometheus

Export Laravel metrics to Prometheus

2651.3M6](/packages/spatie-laravel-prometheus)

PHPackages © 2026

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