{
    "url": "https://delaparra-services.nl/manuals/env-en-omgevingsvariabelen",
    "locale": "en",
    "title": ".env and environment variables · DeLaParra Services",
    "description": "What an .env file is, why it should never be committed to Git, how to add a new setting in Laravel, and what to do if a password has been leaked after all.",
    "alternates": {
        "en": "https://delaparra-services.nl/manuals/env-en-omgevingsvariabelen",
        "nl": "https://delaparra-services.nl/nl/handleidingen/env-en-omgevingsvariabelen"
    },
    "formats": {
        "csv": "https://delaparra-services.nl/manuals/env-en-omgevingsvariabelen.csv",
        "md": "https://delaparra-services.nl/manuals/env-en-omgevingsvariabelen.md",
        "json": "https://delaparra-services.nl/manuals/env-en-omgevingsvariabelen.json",
        "zip": "https://delaparra-services.nl/manuals/env-en-omgevingsvariabelen.zip",
        "pdf": "https://delaparra-services.nl/manuals/env-en-omgevingsvariabelen.pdf"
    },
    "downloads": [
        {
            "url": "https://delaparra-services.nl/manuals/env-en-omgevingsvariabelen.csv",
            "encodingFormat": "text/csv",
            "name": "env-en-omgevingsvariabelen.csv"
        },
        {
            "url": "https://delaparra-services.nl/manuals/env-en-omgevingsvariabelen.json",
            "encodingFormat": "application/json",
            "name": "env-en-omgevingsvariabelen.json"
        },
        {
            "url": "https://delaparra-services.nl/manuals/env-en-omgevingsvariabelen.md",
            "encodingFormat": "text/markdown",
            "name": "env-en-omgevingsvariabelen.md"
        },
        {
            "url": "https://delaparra-services.nl/manuals/env-en-omgevingsvariabelen.pdf",
            "encodingFormat": "application/pdf",
            "name": "env-en-omgevingsvariabelen.pdf"
        },
        {
            "url": "https://delaparra-services.nl/manuals/env-en-omgevingsvariabelen.zip",
            "encodingFormat": "application/zip",
            "name": "env-en-omgevingsvariabelen.zip"
        }
    ],
    "markdown": "# .env and environment variables\n\nYour app has settings that vary depending on the environment (your laptop, the test server, the live server) or that are confidential: database passwords, API keys, the mail server. You shouldn’t put these in your code, but in **environment variables**. In Laravel, these are stored in the `.env` file in your project’s root directory.\n\n```dotenv\nAPP_NAME=\"Mijn App\"\nAPP_ENV=local\nAPP_DEBUG=true\nAPP_URL=http://localhost:8000\n\nDB_CONNECTION=mysql\nDB_HOST=127.0.0.1\nDB_DATABASE=mijnapp\nDB_USERNAME=root\nDB_PASSWORD=geheim\n```\n\n## The golden rule: .env files should never be committed to Git\n\nOtherwise, anyone with access to your repository could see your passwords, even years later. Check that `.env` is included in your `.gitignore`:\n\n```bash\ncat .gitignore | grep .env\n```\n\nWhat *does* go into Git: **`.env.example`**. This file contains all the names, but without any actual values. A new developer (or your AI assistant) copies that file:\n\n```bash\ncp .env.example .env\nphp artisan key:generate\n```\n\n## Add a new institution\n\nSuppose you’re linking a payment provider. In that case, always follow these three steps:\n\n1. \n2. **`.env`**: enter your actual key: `MOLLIE_KEY=test_abc123`.\n3. **`config/services.php`**: load it:\n   ```php\n   'mollie' => [\n       'key' => env('MOLLIE_KEY'),\n   ],\n   ```\n\nYou then use `config('services.mollie.key')` in your code. **Only use `env()` in the files within `config/`.\n\n## Settings on the live server\n\n- Set `APP_ENV=production` and **`APP_DEBUG=false`**. If debugging is enabled, any visitor will be able to see your code – and sometimes your passwords – if an error occurs.\n- After editing `.env` on the server:\n  ```bash\n  php artisan config:clear\n  php artisan config:cache\n  php artisan queue:restart\n  ```\n- Are you using a hosting provider (Laravel Cloud, Forge, a PaaS)? If so, you should enter the variables in their dashboard, not in a file.\n\n## Docker and GitHub Actions\n\n- **Docker:** Use `env_file: .env` to let Compose read the file. Do not set secrets using `ENV` in your Dockerfile, as this will result in them being included in the image.\n- **GitHub Actions:** Set up secrets under *Settings → Secrets and variables → Actions* and use them as `${{ secrets.MOLLIE_KEY }}`.\n\n## Oops: there’s a password in Git\n\n1. **Change the secret immediately** with the provider (new password, new API key). This is the most important step.\n2. Then remove it from your code and put it in `.env`.\n3. Simply clearing the history isn’t enough: someone may already have copied it.\n\n## Need help?\n\nAre you unsure whether there are any secrets lurking in your project? With **AI code review**, I’ll check this for you. A comprehensive, secure setup is an essential part of **bespoke software and web applications**.\n\n## Skills\n\n- [Laravel environment and config] (/nl/skills/laravel-env-config)\n- [Secrets Management] (/nl/skills/secrets-management)\n\n## Related services\n\n- [Maatwerk software en webapplicaties] (/nl/services#service-03)\n- [Beoordeling van AI-code] (/nl/services#service-05)\n\n",
    "structured_data": {
        "@context": "https://schema.org",
        "@graph": [
            {
                "@type": "TechArticle",
                "@id": "https://delaparra-services.nl/manuals/env-en-omgevingsvariabelen#article",
                "url": "https://delaparra-services.nl/manuals/env-en-omgevingsvariabelen",
                "headline": ".env and environment variables",
                "description": "What an .env file is, why it should never be committed to Git, how to add a new setting in Laravel, and what to do if a password has been leaked after all.",
                "inLanguage": "en",
                "subjectOf": {
                    "@id": "https://delaparra-services.nl/manuals/env-en-omgevingsvariabelen#dataset"
                }
            },
            {
                "@type": "Dataset",
                "@id": "https://delaparra-services.nl/manuals/env-en-omgevingsvariabelen#dataset",
                "name": ".env and environment variables",
                "description": "What an .env file is, why it should never be committed to Git, how to add a new setting in Laravel, and what to do if a password has been leaked after all.",
                "url": "https://delaparra-services.nl/manuals/env-en-omgevingsvariabelen",
                "identifier": "https://delaparra-services.nl/manuals/env-en-omgevingsvariabelen#dataset",
                "about": {
                    "@id": "https://delaparra-services.nl/manuals/env-en-omgevingsvariabelen#article"
                },
                "publisher": {
                    "@type": "Organization",
                    "name": "DeLaParra Services",
                    "url": "https://delaparra-services.nl/"
                },
                "isAccessibleForFree": true,
                "inLanguage": "en",
                "isPartOf": {
                    "@type": "Dataset",
                    "@id": "https://delaparra-services.nl/manuals#dataset",
                    "name": "Manuals for working on your own app",
                    "url": "https://delaparra-services.nl/manuals"
                },
                "includedInDataCatalog": {
                    "@type": "DataCatalog",
                    "@id": "https://delaparra-services.nl/knowledge-hub#catalog",
                    "name": "Knowledge hub data catalog",
                    "url": "https://delaparra-services.nl/knowledge-hub"
                },
                "distribution": [
                    {
                        "@type": "DataDownload",
                        "name": "env-en-omgevingsvariabelen.csv",
                        "encodingFormat": "text/csv",
                        "contentUrl": "https://delaparra-services.nl/manuals/env-en-omgevingsvariabelen.csv",
                        "inLanguage": "en"
                    },
                    {
                        "@type": "DataDownload",
                        "name": "env-en-omgevingsvariabelen.json",
                        "encodingFormat": "application/json",
                        "contentUrl": "https://delaparra-services.nl/manuals/env-en-omgevingsvariabelen.json",
                        "inLanguage": "en"
                    },
                    {
                        "@type": "DataDownload",
                        "name": "env-en-omgevingsvariabelen.md",
                        "encodingFormat": "text/markdown",
                        "contentUrl": "https://delaparra-services.nl/manuals/env-en-omgevingsvariabelen.md",
                        "inLanguage": "en"
                    },
                    {
                        "@type": "DataDownload",
                        "name": "env-en-omgevingsvariabelen.pdf",
                        "encodingFormat": "application/pdf",
                        "contentUrl": "https://delaparra-services.nl/manuals/env-en-omgevingsvariabelen.pdf",
                        "inLanguage": "en"
                    },
                    {
                        "@type": "DataDownload",
                        "name": "env-en-omgevingsvariabelen.zip",
                        "encodingFormat": "application/zip",
                        "contentUrl": "https://delaparra-services.nl/manuals/env-en-omgevingsvariabelen.zip",
                        "inLanguage": "en"
                    }
                ]
            }
        ]
    }
}