{"id":16136708,"url":"https://github.com/prinx/dotenv","last_synced_at":"2025-06-20T18:13:01.389Z","repository":{"id":51124908,"uuid":"250278873","full_name":"prinx/dotenv","owner":"prinx","description":"Make easy access to .env file variables in your PHP application","archived":false,"fork":false,"pushed_at":"2021-05-22T14:44:58.000Z","size":105,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-09T11:51:38.463Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/prinx.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-03-26T14:20:00.000Z","updated_at":"2021-05-22T14:42:16.000Z","dependencies_parsed_at":"2022-09-07T07:50:33.928Z","dependency_job_id":null,"html_url":"https://github.com/prinx/dotenv","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/prinx/dotenv","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prinx%2Fdotenv","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prinx%2Fdotenv/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prinx%2Fdotenv/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prinx%2Fdotenv/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/prinx","download_url":"https://codeload.github.com/prinx/dotenv/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prinx%2Fdotenv/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260994007,"owners_count":23094279,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-09T23:12:53.550Z","updated_at":"2025-06-20T18:12:56.378Z","avatar_url":"https://github.com/prinx.png","language":"PHP","readme":"\u003cdiv align=\"center\"\u003e\n\u003ch1\u003ePHP Dotenv\u003c/h1\u003e\n\n[![tests](https://github.com/prinx/dotenv/actions/workflows/tests.yml/badge.svg)](https://github.com/prinx/dotenv/actions/workflows/tests.yml)\n\u003ca href=\"https://travis-ci.com/prinx/dotenv\"\u003e\u003cimg src=\"https://img.shields.io/badge/License-MIT-yellow.svg\"\u003e\u003c/a\u003e\n[![codecov](https://codecov.io/gh/prinx/dotenv/branch/main/graph/badge.svg?token=ZLK6TQXEDQ)](https://codecov.io/gh/prinx/dotenv)\n\u003c/div\u003e\n\nGet easily access to environment variables.\n\n## Installation\n\nOpen a command prompt into your project root folder and run:\n\n```console\ncomposer require prinx/dotenv\n```\n\n## Usage\n\n### Quick start\n\n```php\n// Require composer autoload file if it has not been done yet.\nrequire_once __DIR__ . '/path/to/vendor/autoload.php';\n\n/*\n * Retrieve an environment variable. Returns null if variable not found.\n */\n$hostname = env('DEV_DB_HOST');\n\n/*\n * Retrieve an environment variable. Returns default value passed as second argument if variable not found\n */\n$port = env('DEV_DB_PORT', 3306);\n\n/*\n * Add a variable to the current loaded environment (will not save in the .env file)\n */\naddenv('LOG_LEVEL', 'info');\n\n/*\n * Wrtie variable to the env file. \n * Will also automatically load the variable into the current environment.\n * If the file already contains the variable, the variable will be overwritten.\n */\npersistenv('LOG_LEVEL', 'warn');\npersistenv('LOG_LEVEL', 'debug');\npersistenv('LOG_LEVEL', 'info');\n\n/*\n * Get all environment variables\n */\nenv()\n// OR\nallenv();\n```\n\n### Writing a .env file\n\nThe .env file format will be:\n\n```ini\nVARIABLE_NAME=value\n```\n\nFor example:\n\n```ini\nSESSION_DRIVER=file\nDEV_DB_HOST=localhost\nDEV_DB_PORT=3306\n\nPROD_DB_HOST=prod_db_ip\nPROD_DB_PORT=3308 \n```\n\n\u003e As standard, the variable name is capital letter with underscores to separate words.\n\n#### Comments\n\nYou can write comments in your .env file by preceding the comment by a hash (`#`).\nExample:\n\n```ini\n# Supported: file|database\nSESSION_DRIVER=file\n```\n\n#### Types of values\n\nBy default, env variable will be retrieved as string, except booleans, and null.\n\n##### String\n\nYou can use quotes to surround strings.\n\n```ini\nAPP_NAME=My app\n# or\nAPP_NAME=\"My app\"\n\nDB_HOST=173.0.0.0\n# or\nDB_HOST=\"173.0.0.0\"\n```\n\n##### Boolean\n\nThe values `true`, `\"true\"` or `'true'`, will be got as the boolean `true`.\nThe values `false`, `\"false\"` or `'false'` will be got as the boolean `false`.\n\n```ini\n# Will be got as a boolean true\nAPP_DEBUG=true\n\n# Will be got as a boolean false\nAPP_DEBUG=false\n```\n\nSame as:\n\n```ini\nAPP_DEBUG=\"true\"\n\nAPP_DEBUG=\"false\"\n```\n\n##### Null\n\nThe values `null`, `\"null\"` or `'null'`, will be got as `null`.\n\n```ini\n# Will be got as a null\nAPP_DEBUG=null\n\nAPP_DEBUG=\"null\"\n```\n\n### Referring to another variable\n\nYou can refer to the value of another variable in your .env file by putting the name of the variable you are referring to variable inside ${}:\n\n```ini\n# .env\nSESSION_DRIVER=mysql\nMESSAGE=App based on ${SESSION_DRIVER} database\n```\n\n```php\n// PHP\necho env('MESSAGE'); // App based on mysql database\n```\n\n## Loading a specific .env file\n\nBy default, the package automatically look for the .env file in the project root folder. But you can load the env file from anywhere by using the `loadenv` function:\n\n```php\n// Require composer autoload file if it has not been done yet.\nrequire_once __DIR__ . '/path/to/vendor/autoload.php';\n\nloadenv('/path/to/somewhere/.env');\n\n// Then everything goes as usual\n$apiKey = env('API_KEY');\n```\n\n## Using the Dotenv instance\n\nYou can also get or set a variable using the Dotenv class instance:\n\nThe Dotenv instance can be accessed by calling the `dotenv()` function:\n\n```php\n$dotenv = dotenv();\n```\n\n### Getting a variable\n\n```php\n$hostname = dotenv()-\u003eget('DEV_DB_HOST');\n\n// With a default value\n$hostname = dotenv()-\u003eget('DEV_DB_HOST', 'localhost');\n```\n\n### Getting all variables\n\n```php\n$hostname = dotenv()-\u003eall();\n\n// or use get without any parameter\n$hostname = dotenv()-\u003eget();\n```\n\n### Adding a variable to the current loaded environment\n\n```php\ndotenv()-\u003eadd('GUEST_NAME', 'john');\n```\n\n### Writing a variable to the .env file\n\n```php\ndotenv()-\u003epersist('GUEST_NAME', 'john');\n```\n\n## Create your own Dotenv instance\n\nYou can create your own Dotenv instance just by using the `Dotenv` class:\n\n```php\nuse Prinx\\Dotenv;\n\n$dotenv = new Dotenv('path/to/.env');\n\n$dotenv-\u003eget('VARIABLE');\n```\n\n## Contributing\n\n- Give a star to the repo :relaxed:\n- Fork the repo.\n- Correct a bug, add a new feature.\n- Write tests.\n- Create a pull request.\n\n## License\n\n[MIT](LICENSE)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprinx%2Fdotenv","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fprinx%2Fdotenv","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprinx%2Fdotenv/lists"}