{"id":15527155,"url":"https://github.com/nystudio107/dotenvy","last_synced_at":"2025-04-23T12:16:15.088Z","repository":{"id":57029557,"uuid":"171065615","full_name":"nystudio107/dotenvy","owner":"nystudio107","description":"Speed up your production sites by ditching .env for key/value variable pairs as Apache, Nginx, and shell equivalents","archived":false,"fork":false,"pushed_at":"2019-08-14T20:03:05.000Z","size":43,"stargazers_count":32,"open_issues_count":1,"forks_count":1,"subscribers_count":3,"default_branch":"v1","last_synced_at":"2025-04-23T12:15:53.689Z","etag":null,"topics":["apache","bash","dotenv","env","environment","environment-variables","nginx","php","shell"],"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/nystudio107.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-02-17T00:12:46.000Z","updated_at":"2023-12-13T00:14:41.000Z","dependencies_parsed_at":"2022-08-23T18:50:11.375Z","dependency_job_id":null,"html_url":"https://github.com/nystudio107/dotenvy","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nystudio107%2Fdotenvy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nystudio107%2Fdotenvy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nystudio107%2Fdotenvy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nystudio107%2Fdotenvy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nystudio107","download_url":"https://codeload.github.com/nystudio107/dotenvy/tar.gz/refs/heads/v1","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250430599,"owners_count":21429324,"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":["apache","bash","dotenv","env","environment","environment-variables","nginx","php","shell"],"created_at":"2024-10-02T11:04:46.166Z","updated_at":"2025-04-23T12:16:15.061Z","avatar_url":"https://github.com/nystudio107.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/nystudio107/dotenvy/badges/quality-score.png?b=v1)](https://scrutinizer-ci.com/g/nystudio107/dotenvy/?branch=v1) [![Code Coverage](https://scrutinizer-ci.com/g/nystudio107/dotenvy/badges/coverage.png?b=v1)](https://scrutinizer-ci.com/g/nystudio107/dotenvy/?branch=v1) [![Build Status](https://scrutinizer-ci.com/g/nystudio107/dotenvy/badges/build.png?b=v1)](https://scrutinizer-ci.com/g/nystudio107/dotenvy/build-status/v1) [![Code Intelligence Status](https://scrutinizer-ci.com/g/nystudio107/dotenvy/badges/code-intelligence.svg?b=v1)](https://scrutinizer-ci.com/code-intelligence)\n\n# Dotenvy\n\nSpeed up your production sites by ditching .env for key/value variable pairs as Apache, Nginx, and shell equivalents\n\n## Requirements\n\nPHP 7.0 or later, and a project that uses [Composer](https://getcomposer.org/)\n\n## Installation\n\nTo install this package, follow these instructions.\n\n1. Open your terminal and go to your project:\n\n        cd /path/to/project\n\n2. Then tell Composer to require the package:\n\n        composer require nystudio107/dotenvy\n\n## CraftQuest.io video: Injecting Environment Variables with Dotenvy\n\n[![CraftQuest.io video: Injecting Environment Variables with Dotenvy](https://i.vimeocdn.com/video/769743390.jpg?mw=1900\u0026mh=1069\u0026q=70)](https://craftquest.io/livestreams/injecting-environment-variables-with-dotenvy)\n\n## Dotenvy Overview\n\nDotenvy is a small tool that takes the contents of your `.env` file, and outputs them in a format that can be pasted directly into an Apache server config, Nginx server config, shell CLI `.bashrc`, or Docker `Dockerfile`\n\nWhy? Because as per the [phpdotenv](https://github.com/vlucas/phpdotenv) documentation:\n\n\u003e phpdotenv is made for development environments, and generally should not be used in production. **In production, the actual environment variables should be set so that there is no overhead of loading the .env file on each request.** This can be achieved via an automated deployment process with tools like Vagrant, chef, or Puppet, or can be set manually with cloud hosts like Pagodabox and Heroku.\n  \n  The `.env` file is meant to be a convenience to make things easier to change in local development environments.\n  \n  What the [phpdotenv](https://github.com/vlucas/phpdotenv) package does is parse your `.env` file, and then call [putenv()](http://php.net/manual/en/function.putenv.php) to set each environment variable. This sets the [$_ENV superglobal](http://php.net/manual/en/reserved.variables.environment.php) that your application can later read in via [getenv()](http://php.net/manual/en/function.getenv.php).\n  \n  Using the technique described here, the exact same `$_ENV` superglobal gets set with your environmental variables, and are made available via the same `getenv()` function. The difference is that your webserver or CLI sets the variables directly, without having to parse the `.env` file.\n  \n  Without question, this is a micro-optimization... and is unlikely to make a significant performance difference. But why add overhead for no reason?\n  \n  This is a partial implementation of feature I've been hoping to have in Craft CMS core in some fashion: [Add `craft config/cache` as a console command](https://github.com/craftcms/cms/issues/1607)\n  \n## Using Dotenvy\n\nFrom your project's root directory that contains the `.env` and `/vendor` directory, do:\n\n```bash\nvendor/bin/dotenvy\n```\n\nIf you're on Windows, do:\n```bash\nvendor/bin/dotenvy.bat\n```\n\nIf your `.env` file lives somewhere else, you can pass in the directory to the `.env` file:\n\n```bash\nvendor/bin/dotenvy /path/to/some/dir/\n```\n\nThen **do not create** a `.env` file on your production environment, instead paste or insert via a deployment system the resulting file that Dotenvy generates for you.\n\nIn this way, the appropriate `.env` variables will be automatically injected by your Apache server, or Nginx server, or via CLI.\n\nThis means that the `.env` file no longer needs to be parsed on every request.\n\n### Updating `.gitignore`\n\nMake sure you `.gitignore` all of the `.env*` files with a line like this in your root project `.gitignore` file:\n\n```\n.env*\n```\n...to ensure that none of your secrets in the generated `.env*` files are checked into git. Note the trailing `*`\n\n### Example `.env` file\n\nGiven a `.env` file that looks like this:\n\n```bash\n# The environment Craft is currently running in ('dev', 'staging', 'production', etc.)\nENVIRONMENT=\"local\"\n\n# The secure key Craft will use for hashing and encrypting data\nSECURITY_KEY=\"jMgCxHuaM1g3qSzHiknTt5S8gDy5BNW7\"\n\n# The database driver that will be used ('mysql' or 'pgsql')\nDB_DRIVER=\"mysql\"\n\n# The database server name or IP address (usually this is 'localhost' or '127.0.0.1')\nDB_SERVER=\"localhost\"\n\n# The database username to connect with\nDB_USER=\"homestead\"\n\n# The database password to connect with\nDB_PASSWORD=\"secret\"\n\n# The name of the database to select\nDB_DATABASE=\"craft3\"\n\n# The database schema that will be used (PostgreSQL only)\nDB_SCHEMA=\"public\"\n\n# The prefix that should be added to generated table names (only necessary if multiple things are sharing the same database)\nDB_TABLE_PREFIX=\"\"\n\n# The port to connect to the database with. Will default to 5432 for PostgreSQL and 3306 for MySQL.\nDB_PORT=\"3306\"\n```\n\nThe following files will be output in the same directory as the `.env` file:\n\n#### Apache `.env_apache.txt`\n\nPaste these inside the `\u003cVirtualHost\u003e` block\n\n```apacheconfig\n# Apache .env variables\n# Paste these inside the \u003cVirtualHost\u003e block:\nSetEnv    ENVIRONMENT             \"local\"\nSetEnv    SECURITY_KEY            \"jMgCxHuaM1g3qSzHiknTt5S8gDy5BNW7\"\nSetEnv    DB_DRIVER               \"mysql\"\nSetEnv    DB_SERVER               \"localhost\"\nSetEnv    DB_USER                 \"homestead\"\nSetEnv    DB_PASSWORD             \"secret\"\nSetEnv    DB_DATABASE             \"craft3\"\nSetEnv    DB_SCHEMA               \"public\"\nSetEnv    DB_TABLE_PREFIX         \"\"\nSetEnv    DB_PORT                 \"3306\"\n```\n\n...or you can include the files that Dotenvy generates directly in your Apache conf via:\n\n```\nInclude /home/forge/SOMEDOMAIN/.env_apache.txt\n```\n\n#### Nginx `.env_nginx.txt`\n\nPaste these inside the `server {}` or `location ~ \\.php {}` block or in the `fastcgi_params` file:\n\n```apacheconfig\n# Nginx .env variables\n# Paste these inside the server {} or location ~ \\.php {} block or in the fastcgi_params file:\nfastcgi_param    ENVIRONMENT             \"local\";\nfastcgi_param    SECURITY_KEY            \"jMgCxHuaM1g3qSzHiknTt5S8gDy5BNW7\";\nfastcgi_param    DB_DRIVER               \"mysql\";\nfastcgi_param    DB_SERVER               \"localhost\";\nfastcgi_param    DB_USER                 \"homestead\";\nfastcgi_param    DB_PASSWORD             \"secret\";\nfastcgi_param    DB_DATABASE             \"craft3\";\nfastcgi_param    DB_SCHEMA               \"public\";\nfastcgi_param    DB_TABLE_PREFIX         \"\";\nfastcgi_param    DB_PORT                 \"3306\";\n```\n\n...or you can include the files that Dotenvy generates directly in your Nginx conf via:\n\n```\ninclude /home/forge/SOMEDOMAIN/.env_nginx.txt\n```\n\nSee [Nginx-Craft](https://github.com/nystudio107/nginx-craft) for details.\n\n#### CLI (Bash shell) `.env_cli.txt`\n\nPaste these inside your `.bashrc` file in your `$HOME` directory:\n\n```bash\n# CLI (bash) .env variables\n# Paste these inside your .bashrc file in your $HOME directory:\nexport ENVIRONMENT=\"local\"\nexport SECURITY_KEY=\"jMgCxHuaM1g3qSzHiknTt5S8gDy5BNW7\"\nexport DB_DRIVER=\"mysql\"\nexport DB_SERVER=\"localhost\"\nexport DB_USER=\"homestead\"\nexport DB_PASSWORD=\"secret\"\nexport DB_DATABASE=\"craft3\"\nexport DB_SCHEMA=\"public\"\nexport DB_TABLE_PREFIX=\"\"\nexport DB_PORT=\"3306\"\n```\n\n#### Docker `.env_docker.txt`\n\nPaste these inside your `Dockerfile` file:\n\n```dockerfile\n# Docker .env variables\n# Paste these into your Dockerfile\nENV ENVIRONMENT=\"local\"\nENV SECURITY_KEY=\"jMgCxHuaM1g3qSzHiknTt5S8gDy5BNW7\"\nENV DB_DRIVER=\"mysql\"\nENV DB_SERVER=\"localhost\"\nENV DB_USER=\"homestead\"\nENV DB_PASSWORD=\"secret\"\nENV DB_DATABASE=\"craft3\"\nENV DB_SCHEMA=\"public\"\nENV DB_TABLE_PREFIX=\"\"\nENV DB_PORT=\"3306\"\n```\n\n## The Craft CMS CLI\n\nNote that if you set the `.env` variables directly in your Apache or Nginx config, these variables will **not** be available using the Craft CMS `./craft` CLI command.\n\nThat's because the webserver doesn't run at all for CLI requests. Instead, you'll need to add them to your `.bashrc` file as noted above, or you can use the Unix [source](https://bash.cyberciti.biz/guide/Source_command) command, e.g:\n\n```bash\nsource .env_cli.txt \u0026\u0026 ./craft migrate/all\n```\n\nIn the above example, the `source` command will execute the `export` statements in the `.env_cli.txt` and then run the `./craft` executable with those environmental variables set.\n\nThis pattern is useful if you are running multiple sites on a single instance, and so setting the `.env` variables globally for a user via `.bashrc` doesn't make sense.\n \n## Dotenvy Roadmap\n\nSome things to do, and ideas for potential features:\n\n* Release it\n\nBrought to you by [nystudio107](https://nystudio107.com/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnystudio107%2Fdotenvy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnystudio107%2Fdotenvy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnystudio107%2Fdotenvy/lists"}