Loads environment variables from `.env` to `getenv()`, `$_ENV` and `$_SERVER` automagically.
13.5k
Stars
659
Forks
13
Open issues
30
Contributors
AI Analysis
PHP dotenv loads environment variables from `.env` files into PHP's `getenv()`, `$_ENV`, and `$_SERVER` without manual configuration. It solves the specific problem of managing environment-specific credentials and configuration across different deployment contexts (Apache, Nginx, CLI) while keeping sensitive data out of version control. It is designed for PHP developers building web applications or CLI tools who need portable, zero-configuration environment variable management.
Inferred from signals mentioned in the README (tests, CI, type safety) — not a review of the actual code.
AI's overall editorial judgment — not an average of the bars above, can weigh other factors too.
PHP dotenv loads .env config files into superglobals — a quiet infrastructure staple for millions of PHP apps
phpdotenv solves a concrete, universal problem: how to keep sensitive configuration (API keys, database credentials) out of source code while making it available to PHP applications at runtime. It loads `.env` files into `$_ENV`, `$_SERVER`, and optionally `getenv()`. It is primarily used by PHP application developers following 12-factor app principles, and is deeply embedded in the Laravel ecosystem and broader PHP OSS tooling. With over 330 million Packagist downloads indicated in the badge, it is one of the most widely deployed PHP libraries in existence.
Created in January 2013 as a PHP port of the Ruby dotenv library. Has gone through at least five major versions (V2–V5), each with documented upgrade guides. Maintainership has shifted over time; current active maintainer appears to be GrahamCampbell based on sponsorship references in the README.
Growth was driven primarily by Laravel adopting phpdotenv as a core dependency early on, which gave it massive distribution across the PHP ecosystem. The library's alignment with 12-factor app methodology and the broad shift toward containerized deployments reinforced its relevance. Star growth has plateaued (1 star per 7 days) because the library is mature and saturated in its niche — not because it's declining.
Packagist download badge claims hundreds of millions of total downloads. Laravel framework depends on it as a first-class dependency, meaning every Laravel application (a very large fraction of PHP production deployments globally) uses it indirectly. This is among the strongest adoption signals available in the PHP ecosystem.
Appears to follow a clean OOP design with clear separation between immutable and mutable loading modes (`createImmutable` vs `createMutable`), a repository/adapter pattern for environment variable storage (implied by `PutenvAdapter` reference), and support for variable nesting and validation. Likely uses PHP 7.x+ features given V5 vintage.
Not documented in README, but given the project's maturity, wide adoption, and active maintenance history, test coverage is likely present — cannot verify depth or tooling from available metadata.
Last push was 2025-12-27, approximately 6 months before the evaluation date. For a mature, stable utility library this cadence is acceptable — it suggests the project is feature-complete and maintained on a fix/security basis rather than actively developed. Not stagnant; simply mature.
ADOPT IF: you are building a PHP application outside of a full Symfony stack and need a simple, reliable way to load .env files for local development or non-containerized deployments. AVOID IF: you are using Symfony (prefer symfony/dotenv) or running fully containerized workloads where env vars are injected by the orchestrator — phpdotenv adds unnecessary overhead in those contexts. MONITOR IF: you are on an older major version (V3/V4) and need to evaluate upgrade cost to V5 given breaking change history between major versions.
Independent dimensions
Mainstream potential
3/10
Technical importance
6/10
Adoption evidence
9/10
- In fully containerized environments (Docker, Kubernetes), .env file loading may be redundant or even counterproductive if secrets management is handled at the infrastructure level.
- Thread safety limitation: the README itself warns against `getenv()`/`putenv()` use in multi-threaded PHP contexts (e.g., PHP with certain SAPIs), which may surprise developers unaware of the distinction.
- Major version upgrades have historically introduced breaking changes; projects that have not kept pace with V5 may face non-trivial migration effort.
- Maintainer concentration risk: active maintenance appears to depend significantly on GrahamCampbell (referenced in sponsorship section); contributor bus factor is unclear from available metadata.
- As infrastructure-as-code and secrets managers (AWS Secrets Manager, Vault, etc.) become more common, the .env pattern may slowly lose relevance in professional production environments, though local development use will likely persist.
phpdotenv will remain a widely used, slowly declining-in-novelty infrastructure library. It has effectively won its niche in PHP and will maintain high download counts driven by Laravel and legacy codebases for many years, but new project greenfield adoption may gradually shift toward framework-native solutions or infrastructure-level env injection.
Explore similar
Newsletter
Get analyses like this every Monday
Free weekly digest of the most interesting open-source discoveries.
Languages
Information
- Language
- PHP
- License
- BSD-3-Clause
- Last updated
- 4d ago
- Created
- 164mo ago
- Analyzed with
- anthropic/claude-haiku-4-5
Stars over time
Contributors over time
Top 100 contributors only — repos with more will plateau at 100.
Open issues
Add `withDefault` method & caster for Validator
[Discussion] Is using phpdotenv a replacement for a `config.php`?
strange behavior with ImmutableWriter::isExternallyDefined()
How should I use `notEmpty`?
Nesting Variables do not work for me on a raspberry
Top contributors
Similar repos
| Repository | Stars | Week Δ | Language | Score | Updated |
|---|---|---|---|---|---|
|
|
13.5k | +3 | PHP | 8/10 | 4d ago |
|
|
20.5k | — | JavaScript | 9/10 | 4w ago |
|
|
3.8k | — | PHP | 8/10 | 2w ago |
|
|
5.6k | — | JavaScript | 8/10 | 9h ago |
|
|
10.5k | — | Go | 8/10 | 3w ago |
|
|
6.8k | — | Ruby | 9/10 | 7mo ago |
Symfony's own component serves the same purpose and is preferred within Symfony-based projects. It offers tighter framework integration and supports additional file formats like `.env.local`. phpdotenv is more framework-agnostic but both are mature.
The original Ruby library that inspired phpdotenv. Not a competitor — serves a different language ecosystem. Comparable adoption within Ruby.
A lesser-known PHP alternative with far fewer downloads and community adoption. phpdotenv vastly dominates in the PHP space.
In containerized production environments, .env files are often replaced by orchestrator-level env injection. phpdotenv remains useful for local development and simpler deployments but is less relevant when infrastructure handles env vars natively.
Not a direct competitor — Deployer handles deployment orchestration, not runtime environment variable loading. They address different stages of the deployment lifecycle.
