{"id":15652124,"url":"https://github.com/bnomei/kirby3-dotenv","last_synced_at":"2025-04-06T13:11:56.016Z","repository":{"id":37548973,"uuid":"162300062","full_name":"bnomei/kirby3-dotenv","owner":"bnomei","description":"Kirby Plugin for environment variables from .env files","archived":false,"fork":false,"pushed_at":"2024-11-27T15:12:16.000Z","size":255,"stargazers_count":37,"open_issues_count":1,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-30T12:09:11.312Z","etag":null,"topics":["dotenv","dotenv-loader","enviroment-variables","kirby","kirby-cms","kirby-plugin","kirby4","kirby5"],"latest_commit_sha":null,"homepage":"https://forum.getkirby.com/t/kirby3-dotenv-load-enviroment-variables-from-env-files/23578","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/bnomei.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"bnomei","patreon":"bnomei","open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":["https://buymeacoff.ee/bnomei","https://paypal.me/bnomei"]}},"created_at":"2018-12-18T14:26:11.000Z","updated_at":"2025-02-16T22:45:38.000Z","dependencies_parsed_at":"2024-06-21T17:38:36.889Z","dependency_job_id":"28a8782a-d949-47c8-b630-b26539ab20ff","html_url":"https://github.com/bnomei/kirby3-dotenv","commit_stats":{"total_commits":54,"total_committers":2,"mean_commits":27.0,"dds":0.01851851851851849,"last_synced_commit":"fe5d63d9e1537a5d7f4668db0585ccd3d56596c9"},"previous_names":[],"tags_count":23,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bnomei%2Fkirby3-dotenv","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bnomei%2Fkirby3-dotenv/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bnomei%2Fkirby3-dotenv/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bnomei%2Fkirby3-dotenv/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bnomei","download_url":"https://codeload.github.com/bnomei/kirby3-dotenv/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247485290,"owners_count":20946398,"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":["dotenv","dotenv-loader","enviroment-variables","kirby","kirby-cms","kirby-plugin","kirby4","kirby5"],"created_at":"2024-10-03T12:41:25.558Z","updated_at":"2025-04-06T13:11:56.000Z","avatar_url":"https://github.com/bnomei.png","language":"PHP","funding_links":["https://github.com/sponsors/bnomei","https://patreon.com/bnomei","https://buymeacoff.ee/bnomei","https://paypal.me/bnomei","https://www.buymeacoffee.com/bnomei"],"categories":[],"sub_categories":[],"readme":"# Kirby DotEnv\n\n[![Kirby 5](https://flat.badgen.net/badge/Kirby/5?color=ECC748)](https://getkirby.com)\n![PHP 8.2](https://flat.badgen.net/badge/PHP/8.2?color=4E5B93\u0026icon=php\u0026label)\n![Release](https://flat.badgen.net/packagist/v/bnomei/kirby3-dotenv?color=ae81ff\u0026icon=github\u0026label)\n![Downloads](https://flat.badgen.net/packagist/dt/bnomei/kirby3-dotenv?color=272822\u0026icon=github\u0026label)\n[![Coverage](https://flat.badgen.net/codeclimate/coverage/bnomei/kirby3-dotenv?icon=codeclimate\u0026label)](https://codeclimate.com/github/bnomei/kirby3-dotenv)\n[![Maintainability](https://flat.badgen.net/codeclimate/maintainability/bnomei/kirby3-dotenv?icon=codeclimate\u0026label)](https://codeclimate.com/github/bnomei/kirby3-dotenv/issues)\n[![Discord](https://flat.badgen.net/badge/discord/bnomei?color=7289da\u0026icon=discord\u0026label)](https://discordapp.com/users/bnomei)\n[![Buymecoffee](https://flat.badgen.net/badge/icon/donate?icon=buymeacoffee\u0026color=FF813F\u0026label)](https://www.buymeacoffee.com/bnomei)\n\nKirby Plugin for environment variables from .env files\n\n## Installation\n\n- unzip [master.zip](https://github.com/bnomei/kirby3-dotenv/archive/master.zip) as folder `site/plugins/kirby3-dotenv`\n  or\n- `git submodule add https://github.com/bnomei/kirby3-dotenv.git site/plugins/kirby3-dotenv` or\n- `composer require bnomei/kirby3-dotenv`\n\n## Usage\n\nCreate a `.env` file in the root of your Kirby installation. Within your Kirby project you can access the environment variables using various PHP helper functions.\n\n### in production or with default environment\n\nBased on an environment like\n- `/site/config/config.php` Kirby configuration file and given a\n- `/.env` file.\n\n**/.env**\n\n```dotenv\nAPP_MODE=production\nAPP_DEBUG=false\nALGOLIA_APIKEY=12d7331a21d8a28b3069c49830f463e833e30f6d\nKIRBY_API_USER=bnomei\nKIRBY_API_PW=52d3a0edcc78be6c5645fdb7568f94d3d83d1c2a\n```\n\n```php\n\u003c?php\necho $_ENV['APP_MODE']; // production\necho env('APP_DEBUG');  // false\n// or\necho $page-\u003egetenv('ALGOLIA_APIKEY');  // 12d7331...\necho $page-\u003eenv('ALGOLIA_APIKEY');     // 12d7331...\necho site()-\u003egetenv('ALGOLIA_APIKEY'); // 12d7331...\necho site()-\u003eenv('ALGOLIA_APIKEY');    // 12d7331...\n```\n\n### on local or staging test server\n\nYou can also create files to have different settings for different environments.\nThe plugin will try to automatically load the correct file based on the environment.\n\nBased on an environment like \n- http://dotenv.test matching a \n- `/site/config/config.dotenv.test.php` Kirby configuration file and given a \n- `/.env.dotenv.test` file.\n\n**/.env.dotenv.test**\n```dotenv\nAPP_MODE=staging\nAPP_DEBUG=true\nALGOLIA_APIKEY=950306d052ec893b467f2ca088daf2964b9f9530\nKIRBY_API_USER=notBnomei\nKIRBY_API_PW=37e30ad867ff3a427317dcd1852abbd692b39ffc\n```\n\n```php\n\u003c?php\necho $_ENV['APP_MODE']; // staging\necho env('APP_DEBUG');  // true\n// ...\n```\n\n## Default values\n\nIn case you want to provide a default value as fallback in case the environment variable is not set you can do that with\nthe 2nd parameter in each helper function. Thanks for your PR @teichsta.\n\n```php\n\u003c?php\n// `true` as default value\necho env('ALGOLIA_ENABLED', true);\n```\n\n## Usage in Config files might require a manual load\n\nThe environment variables set by your hosting service are available in your PHP scripts by default using the `$_ENV` super-global and the `getenv()` function. They are injected into the PHP environment by the web server.\n\nBut the values from the `.env` files are NOT available in the same way. They need to be loaded manually. The Dotenv plugin will load these on it's first usage. But the plugin can only do so automatically once it has been loaded itself which is after the config files have been parsed by Kirby.\n\n### Using Callbacks or the Ready Option\n\nWhere possible you should use the `callback` option to provide a function that returns the value you need. Once the callback is called the `.env` file will already have been loaded and the value will be available. Not all options support callbacks though.\n\n**/site/config/config.php**\n```php\n\u003c?php\nreturn [\n    // does not support callbacks\n    // 'debug' =\u003e false, \n\n    // some plugins support callbacks for sensitive data options\n    'bnomei.seobility.apikey' =\u003e function() { \n        return env('SEOBILITY_APIKEY'); \n    },\n    \n    // alternatively you can use the `ready` option\n    // https://getkirby.com/docs/reference/system/options/ready\n    'ready' =\u003e function() {\n        return [\n            'debug' =\u003e env('APP_DEBUG', false),\n            'email' =\u003e [\n                'transport' =\u003e [\n                    'type' =\u003e 'smtp',\n                    'host' =\u003e 'smtp.postmarkapp.com',\n                    'port' =\u003e 587,\n                    'security' =\u003e true,\n                    'auth' =\u003e true,\n                    'username' =\u003e env('POSTMARK_USERNAME'),\n                    'password' =\u003e env('POSTMARK_PASSWORD'),\n                ],\n            ],\n        ];\n    }\n];\n```\n\n### Manually load the .env file in the config file\n\nIf you still decide you need to use the values from the `.env` files in the config files of Kirby directly, you can manually initialize the loading of these like so:\n\n**/site/config/config.php**\n```php\n\u003c?php\n\nrequire_once __DIR__ . '/../plugins/kirby3-dotenv/global.php';\nloadenv();\n\nreturn [\n    'debug' =\u003e env('APP_DEBUG', false),\n    //...\n];\n```\n\nYou can provide a custom options as an array to that function if you want to force loading a specific directory or file.\n\n## Other Environment Variables Sources\n\nIf you set environment variables in your server configuration these will be available as well.\n\n\u003e [!WARNING]\n\u003e This plugin will load environment variables from `.env` files and potentially overwrite existing environment\n\u003e variables.\n\n## In the CLI\n\nWhen running Kirby commands in the CLI make sure you prefix the command with the environment variable for the HOST you want to use.\n\n```sh\nenv KIRBY_HOST=dotenv.test kirby my:command\n```\n\n## Similar Plugins\n\n- [beebmx/kirby-env](https://github.com/beebmx/kirby-env)\n- [johannschopplich/kirby-extended](https://github.com/johannschopplich/kirby-extended)\n\n## Settings\n\n| bnomei.dotenv. | Default          | Description                                                                                                                                              |            \n|----------------|------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------|\n| dir            | `callback`       | returning `kirby()-\u003eroots()-\u003eindex().` When installing Kirby 3 with Composer use a `function() { return realpath(kirby()-\u003eroots()-\u003eindex() . '/../'); }` | \n| file           | `.env`           |                                                                                                                                                          |\n| environment    | `callback`       | auto-detection for the current environment                                                                                                               |\n| required       | `callback or []` | You can define required variables in the settings using an array. If any of these is missing a `RuntimeException` will be thrown.                        |\n| setup          | `callback`       | perform additional tasks on raw dotenv class instance                                                                                                    |\n\n## Dependencies\n\n- [vlucas/phpdotenv](https://github.com/vlucas/phpdotenv)\n\n## Disclaimer\n\nThis plugin is provided \"as is\" with no guarantee. Use it at your own risk and always test it yourself before using it\nin a production environment. If you find any issues,\nplease [create a new issue](https://github.com/bnomei/kirby3-dotenv/issues/new).\n\n## License\n\n[MIT](https://opensource.org/licenses/MIT)\n\nIt is discouraged to use this plugin in any project that promotes racism, sexism, homophobia, animal abuse, violence or\nany other form of hate speech.\n\n## Credits\n\nbased on K2 version of\n\n- https://github.com/jevets/kirby-phpdotenv\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbnomei%2Fkirby3-dotenv","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbnomei%2Fkirby3-dotenv","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbnomei%2Fkirby3-dotenv/lists"}