[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-8138":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":10,"language":11,"languages":10,"totalLinesOfCode":10,"stars":12,"forks":13,"watchers":14,"openIssues":15,"contributorsCount":16,"subscribersCount":16,"size":16,"stars1d":16,"stars7d":16,"stars30d":17,"stars90d":16,"forks30d":16,"starsTrendScore":16,"compositeScore":18,"rankGlobal":10,"rankLanguage":10,"license":19,"archived":20,"fork":20,"defaultBranch":21,"hasWiki":20,"hasPages":20,"topics":22,"createdAt":10,"pushedAt":10,"updatedAt":29,"readmeContent":30,"aiSummary":31,"trendingCount":16,"starSnapshotCount":16,"syncStatus":32,"lastSyncTime":33,"discoverSource":34},8138,"phpdotenv","vlucas\u002Fphpdotenv","vlucas","Loads environment variables from `.env` to `getenv()`, `$_ENV` and `$_SERVER` automagically.","",null,"PHP",13539,658,165,14,0,9,69.36,"BSD 3-Clause \"New\" or \"Revised\" License",false,"master",[23,24,25,26,27,28],"configuration","dotenv","environment","environment-variables","hacktoberfest","php","2026-06-12 04:00:37","PHP dotenv\n==========\n\nLoads environment variables from `.env` to `getenv()`, `$_ENV` and `$_SERVER` automagically.\n\n![Banner](https:\u002F\u002Fuser-images.githubusercontent.com\u002F2829600\u002F71564012-31105580-2a91-11ea-9ad7-ef1278411b35.png)\n\n\u003Cp align=\"center\">\n\u003Ca href=\"LICENSE\">\u003Cimg src=\"https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Flicense-BSD%203--Clause-brightgreen.svg?style=flat-square\" alt=\"Software License\">\u003C\u002Fimg>\u003C\u002Fa>\n\u003Ca href=\"https:\u002F\u002Fpackagist.org\u002Fpackages\u002Fvlucas\u002Fphpdotenv\">\u003Cimg src=\"https:\u002F\u002Fimg.shields.io\u002Fpackagist\u002Fdt\u002Fvlucas\u002Fphpdotenv.svg?style=flat-square\" alt=\"Total Downloads\">\u003C\u002Fimg>\u003C\u002Fa>\n\u003Ca href=\"https:\u002F\u002Fgithub.com\u002Fvlucas\u002Fphpdotenv\u002Freleases\">\u003Cimg src=\"https:\u002F\u002Fimg.shields.io\u002Fgithub\u002Frelease\u002Fvlucas\u002Fphpdotenv.svg?style=flat-square\" alt=\"Latest Version\">\u003C\u002Fimg>\u003C\u002Fa>\n\u003C\u002Fp>\n\n\u003Cdiv align=\"center\">\n\n**Special thanks to [our sponsors](https:\u002F\u002Fgithub.com\u002Fsponsors\u002FGrahamCampbell)**\n\n\u003Chr>\n\u003C\u002Fdiv>\n\n\n## Why .env?\n\n**You should never store sensitive credentials in your code**. Storing\n[configuration in the environment](https:\u002F\u002Fwww.12factor.net\u002Fconfig) is one of\nthe tenets of a [twelve-factor app](https:\u002F\u002Fwww.12factor.net\u002F). Anything that\nis likely to change between deployment environments – such as database\ncredentials or credentials for 3rd party services – should be extracted from\nthe code into environment variables.\n\nBasically, a `.env` file is an easy way to load custom configuration variables\nthat your application needs without having to modify .htaccess files or\nApache\u002Fnginx virtual hosts. This means you won't have to edit any files outside\nthe project, and all the environment variables are always set no matter how you\nrun your project - Apache, Nginx, CLI, and even PHP's built-in webserver. It's\nWAY easier than all the other ways you know of to set environment variables,\nand you're going to love it!\n\n* NO editing virtual hosts in Apache or Nginx\n* NO adding `php_value` flags to .htaccess files\n* EASY portability and sharing of required ENV values\n* COMPATIBLE with PHP's built-in web server and CLI runner\n\nPHP dotenv is a PHP version of the original [Ruby\ndotenv](https:\u002F\u002Fgithub.com\u002Fbkeepers\u002Fdotenv).\n\n\n## Installation\n\nInstallation is super-easy via [Composer](https:\u002F\u002Fgetcomposer.org\u002F):\n\n```bash\n$ composer require vlucas\u002Fphpdotenv\n```\n\nor add it by hand to your `composer.json` file.\n\n\n## Upgrading\n\nWe follow [semantic versioning](https:\u002F\u002Fsemver.org\u002F), which means breaking\nchanges may occur between major releases. We have upgrading guides available\nfor V2 to V3, V3 to V4 and V4 to V5 available [here](UPGRADING.md).\n\n\n## Usage\n\nThe `.env` file is generally kept out of version control since it can contain\nsensitive API keys and passwords. A separate `.env.example` file is created\nwith all the required environment variables defined except for the sensitive\nones, which are either user-supplied for their own development environments or\nare communicated elsewhere to project collaborators. The project collaborators\nthen independently copy the `.env.example` file to a local `.env` and ensure\nall the settings are correct for their local environment, filling in the secret\nkeys or providing their own values when necessary. In this usage, the `.env`\nfile should be added to the project's `.gitignore` file so that it will never\nbe committed by collaborators.  This usage ensures that no sensitive passwords\nor API keys will ever be in the version control history so there is less risk\nof a security breach, and production values will never have to be shared with\nall project collaborators.\n\nAdd your application configuration to a `.env` file in the root of your\nproject. **Make sure the `.env` file is added to your `.gitignore` so it is not\nchecked-in the code**\n\n```shell\nS3_BUCKET=\"dotenv\"\nSECRET_KEY=\"souper_seekret_key\"\n```\n\nNow create a file named `.env.example` and check this into the project. This\nshould have the ENV variables you need to have set, but the values should\neither be blank or filled with dummy data. The idea is to let people know what\nvariables are required, but not give them the sensitive production values.\n\n```shell\nS3_BUCKET=\"devbucket\"\nSECRET_KEY=\"abc123\"\n```\n\nYou can then load `.env` in your application with:\n\n```php\n$dotenv = Dotenv\\Dotenv::createImmutable(__DIR__);\n$dotenv->load();\n```\n\nTo suppress the exception that is thrown when there is no `.env` file, you can:\n\n```php\n$dotenv = Dotenv\\Dotenv::createImmutable(__DIR__);\n$dotenv->safeLoad();\n```\n\nOptionally you can pass in a filename as the second parameter, if you would\nlike to use something other than `.env`:\n\n```php\n$dotenv = Dotenv\\Dotenv::createImmutable(__DIR__, 'myconfig');\n$dotenv->load();\n```\n\nAll of the defined variables are now available in the `$_ENV` and `$_SERVER`\nsuper-globals.\n\n```php\n$s3_bucket = $_ENV['S3_BUCKET'];\n$s3_bucket = $_SERVER['S3_BUCKET'];\n```\n\n\n### Putenv and Getenv\n\nUsing `getenv()` and `putenv()` is strongly discouraged due to the fact that\nthese functions are not thread safe, however it is still possible to instruct\nPHP dotenv to use these functions. Instead of calling\n`Dotenv::createImmutable`, one can call `Dotenv::createUnsafeImmutable`, which\nwill add the `PutenvAdapter` behind the scenes. Your environment variables will\nnow be available using the `getenv` method, as well as the super-globals:\n\n```php\n$s3_bucket = getenv('S3_BUCKET');\n$s3_bucket = $_ENV['S3_BUCKET'];\n$s3_bucket = $_SERVER['S3_BUCKET'];\n```\n\n\n### Nesting Variables\n\nIt's possible to nest an environment variable within another, useful to cut\ndown on repetition.\n\nThis is done by wrapping an existing environment variable in `${…}` e.g.\n\n```shell\nBASE_DIR=\"\u002Fvar\u002Fwebroot\u002Fproject-root\"\nCACHE_DIR=\"${BASE_DIR}\u002Fcache\"\nTMP_DIR=\"${BASE_DIR}\u002Ftmp\"\n```\n\n\n### Immutability and Repository Customization\n\nImmutability refers to if Dotenv is allowed to overwrite existing environment\nvariables. If you want Dotenv to overwrite existing environment variables,\nuse `createMutable` instead of `createImmutable`:\n\n```php\n$dotenv = Dotenv\\Dotenv::createMutable(__DIR__);\n$dotenv->load();\n```\n\nBehind the scenes, this is instructing the \"repository\" to allow immutability\nor not. By default, the repository is configured to allow overwriting existing\nvalues by default, which is relevant if one is calling the \"create\" method\nusing the `RepositoryBuilder` to construct a more custom repository:\n\n```php\n$repository = Dotenv\\Repository\\RepositoryBuilder::createWithNoAdapters()\n    ->addAdapter(Dotenv\\Repository\\Adapter\\EnvConstAdapter::class)\n    ->addWriter(Dotenv\\Repository\\Adapter\\PutenvAdapter::class)\n    ->immutable()\n    ->make();\n\n$dotenv = Dotenv\\Dotenv::create($repository, __DIR__);\n$dotenv->load();\n```\n\nThe above example will write loaded values to `$_ENV` and `putenv`, but when\ninterpolating environment variables, we'll only read from `$_ENV`. Moreover, it\nwill never replace any variables already set before loading the file.\n\nBy means of another example, one can also specify a set of variables to be\nallow listed. That is, only the variables in the allow list will be loaded:\n\n```php\n$repository = Dotenv\\Repository\\RepositoryBuilder::createWithDefaultAdapters()\n    ->allowList(['FOO', 'BAR'])\n    ->make();\n\n$dotenv = Dotenv\\Dotenv::create($repository, __DIR__);\n$dotenv->load();\n```\n\n\n### Requiring Variables to be Set\n\nPHP dotenv has built in validation functionality, including for enforcing the\npresence of an environment variable. This is particularly useful to let people\nknow any explicit required variables that your app will not work without.\n\nYou can use a single string:\n\n```php\n$dotenv->required('DATABASE_DSN');\n```\n\nOr an array of strings:\n\n```php\n$dotenv->required(['DB_HOST', 'DB_NAME', 'DB_USER', 'DB_PASS']);\n```\n\nIf any ENV vars are missing, Dotenv will throw a `RuntimeException` like this:\n\n```\nOne or more environment variables failed assertions: DATABASE_DSN is missing\n```\n\n\n### Empty Variables\n\nBeyond simply requiring a variable to be set, you might also need to ensure the\nvariable is not empty:\n\n```php\n$dotenv->required('DATABASE_DSN')->notEmpty();\n```\n\nIf the environment variable is empty, you'd get an Exception:\n\n```\nOne or more environment variables failed assertions: DATABASE_DSN is empty\n```\n\n\n### Integer Variables\n\nYou might also need to ensure that the variable is of an integer value. You may\ndo the following:\n\n```php\n$dotenv->required('FOO')->isInteger();\n```\n\nIf the environment variable is not an integer, you'd get an Exception:\n\n```\nOne or more environment variables failed assertions: FOO is not an integer.\n```\n\nOne may only want to enforce validation rules when a variable is set. We\nsupport this too:\n\n```php\n$dotenv->ifPresent('FOO')->isInteger();\n```\n\n\n### Boolean Variables\n\nYou may need to ensure a variable is in the form of a boolean, accepting\n\"true\", \"false\", \"On\", \"1\", \"Yes\", \"Off\", \"0\" and \"No\". You may do the\nfollowing:\n\n```php\n$dotenv->required('FOO')->isBoolean();\n```\n\nIf the environment variable is not a boolean, you'd get an Exception:\n\n```\nOne or more environment variables failed assertions: FOO is not a boolean.\n```\n\nSimilarly, one may write:\n\n```php\n$dotenv->ifPresent('FOO')->isBoolean();\n```\n\n\n### Allowed Values\n\nIt is also possible to define a set of values that your environment variable\nshould be. This is especially useful in situations where only a handful of\noptions or drivers are actually supported by your code:\n\n```php\n$dotenv->required('SESSION_STORE')->allowedValues(['Filesystem', 'Memcached']);\n```\n\nIf the environment variable wasn't in this list of allowed values, you'd get a\nsimilar Exception:\n\n```\nOne or more environment variables failed assertions: SESSION_STORE is not an allowed value.\n```\n\nIt is also possible to define a regex that your environment variable should be.\n```php\n$dotenv->required('FOO')->allowedRegexValues('([[:lower:]]{3})');\n```\n\n\n### Comments\n\nYou can comment your `.env` file using the `#` character. E.g.\n\n```shell\n# this is a comment\nVAR=\"value\" # comment\nVAR=value # comment\n```\n\n\n### Parsing Without Loading\n\nSometimes you just wanna parse the file and resolve the nested environment variables, by giving us a string, and have an array returned back to you. While this is already possible, it is a little fiddly, so we have provided a direct way to do this:\n\n```php\n\u002F\u002F ['FOO' => 'Bar', 'BAZ' => 'Hello Bar']\nDotenv\\Dotenv::parse(\"FOO=Bar\\nBAZ=\\\"Hello \\${FOO}\\\"\");\n```\n\nThis is exactly the same as:\n\n```php\nDotenv\\Dotenv::createArrayBacked(__DIR__)->load();\n```\n\nonly, instead of providing the directory to find the file, you have directly provided the file contents.\n\n\n### Usage Notes\n\nWhen a new developer clones your codebase, they will have an additional\none-time step to manually copy the `.env.example` file to `.env` and fill-in\ntheir own values (or get any sensitive values from a project co-worker).\n\n\n### Troubleshooting\n\nIn certain server setups (most commonly found in shared hosting), PHP might deactivate superglobals like `$_ENV` or `$_SERVER`. If these variables are not set, review the `variables_order` in the `php.ini` file. See [php.net\u002Fmanual\u002Fen\u002Fini.core.php#ini.variables-order](https:\u002F\u002Fwww.php.net\u002Fmanual\u002Fen\u002Fini.core.php#ini.variables-order).\n\n## Security\n\nIf you discover a security vulnerability within this package, please send an email to security@tidelift.com. All security vulnerabilities will be promptly addressed. You may view our full security policy [here](https:\u002F\u002Fgithub.com\u002Fvlucas\u002Fphpdotenv\u002Fsecurity\u002Fpolicy).\n\n\n## License\n\nPHP dotenv is licensed under [The BSD 3-Clause License](LICENSE).\n\n\n## For Enterprise\n\nAvailable as part of the Tidelift Subscription\n\nThe maintainers of `vlucas\u002Fphpdotenv` and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. [Learn more.](https:\u002F\u002Ftidelift.com\u002Fsubscription\u002Fpkg\u002Fpackagist-vlucas-phpdotenv?utm_source=packagist-vlucas-phpdotenv&utm_medium=referral&utm_campaign=enterprise&utm_term=repo)\n","vlucas\u002Fphpdotenv 是一个用于从 `.env` 文件中自动加载环境变量到 `getenv()`、`$_ENV` 和 `$_SERVER` 的 PHP 库。其核心功能包括简化配置管理，通过将敏感信息如数据库凭证等存储在环境变量中而非代码里，从而提高安全性与可移植性。它支持多种运行环境，无论是使用 Apache、Nginx 还是 PHP 内置服务器或命令行接口都能无缝工作。非常适合需要跨不同部署环境（如开发、测试、生产）保持一致配置的应用程序开发者使用。",2,"2026-06-11 03:16:22","top_language"]