Cloud deployments become easier to operate when configuration is explicit, secrets are protected, and every environment can be checked consistently. This guide provides a platform-neutral workflow for setting environment variables, separating configuration from credentials, reviewing development, staging, and production differences, and responding safely when a secret may have leaked.
Overview
Environment variables are named values supplied to an application at runtime or during a build. They are useful for settings that change between environments, such as database hosts, public site URLs, feature flags, log levels, and API endpoints. Secrets are a narrower category: passwords, private tokens, signing keys, webhook credentials, and other values that could enable unauthorized access.
The important distinction is not whether a value appears in a file called .env. A value is sensitive because of what it grants or reveals. Treating every variable as public can expose credentials, while treating every value as a secret can make ordinary configuration harder to review and maintain.
A reliable cloud hosting workflow has four properties:
- Separation: development, staging, and production have distinct values and access boundaries.
- Traceability: the team knows which application version expects each variable and what the variable controls.
- Limited exposure: secrets are not committed to repositories, printed in logs, embedded in client-side code, or shared more broadly than necessary.
- Recoverability: credentials can be rotated, deployments can be rolled back, and a suspected leak has an assigned response process.
Use the hosting dashboard, deployment platform, CI/CD system, or cloud secret store available in your stack, but apply the same principles regardless of provider. Before moving a site to managed cloud hosting, this configuration review should sit alongside a migration and rollback plan. The website migration to cloud hosting checklist can help organize that wider cutover.
What to track
Configuration versus secrets
Start with an inventory rather than copying an existing .env file into a production dashboard. For each variable, record its name, purpose, required environment, owner, sensitivity, source, and rotation or review expectation.
| Category | Examples | Typical handling |
|---|---|---|
| Public configuration | Site URL, public analytics identifier, feature flag | May be visible to users; still validate values and environment scope |
| Private configuration | Internal service URL, queue name, database name | Keep server-side and limit access where disclosure could reveal infrastructure |
| Credentials | API token, database password, SMTP password | Store in a secret manager or protected deployment setting; never commit to source |
| Cryptographic material | Signing key, encryption key, private certificate key | Use tightly controlled storage, narrow permissions, and a documented rotation plan |
A variable prefixed with a framework convention such as PUBLIC_, VITE_, or a similar client-exposure marker may be bundled into browser code. Verify your framework’s current behavior before placing anything sensitive under such a name. A secret required only by server code should not be exposed through a client-readable prefix.
Naming conventions and required values
Choose names that describe purpose rather than implementation details. Names such as DATABASE_URL, PAYMENTS_API_BASE_URL, and SESSION_SIGNING_KEY are easier to audit than vague names such as KEY or CONFIG2. Use one consistent case convention, separate words with underscores, and avoid changing a variable’s meaning across releases.
Document whether each variable is required, optional, public, or environment-specific. Applications should fail clearly when a required production variable is absent. A startup validation step is preferable to allowing a missing value to cause an obscure error during a customer request.
Development, staging, and production
These environments should be similar enough to expose deployment problems but separate enough to prevent testing against live customer data or production services. Keep separate credentials, databases, storage buckets, email accounts, and third-party projects whenever practical.
| Environment | Primary purpose | Access and data guidance |
|---|---|---|
| Development | Local coding and debugging | Use disposable or synthetic data; keep local files untracked and protect developer machines |
| Staging | Release verification and integration testing | Mirror production configuration shape without reusing production credentials or sensitive data |
| Production | Live traffic and business operations | Use the narrowest permissions, controlled access, audit records, backups, and tested rollback procedures |
Runtime examples
In a Node.js application, server-side code commonly reads values through process.env.DATABASE_URL. In Python, an application may read os.environ["DATABASE_URL"]. In PHP, values may be accessed through the process environment. The syntax differs, but the deployment rule is the same: inject values at runtime or through the platform’s supported build configuration, and do not hard-code credentials in application files.
Pay particular attention to build-time versus runtime behavior. Some static site builders replace variables while generating browser assets, which makes those values public. Server-rendered applications may read variables when the process starts, while a containerized service may receive them when the container is launched. Confirm when your framework evaluates each variable before assuming that changing a dashboard value will affect already-built assets.
Cadence and checkpoints
Secrets management is not a one-time setup task. Maintain a lightweight register and review it on a monthly or quarterly cadence, depending on the application’s risk and release frequency. The goal is to catch drift before it becomes an outage or security incident.
At every deployment
- Compare the release’s required variables with the target environment.
- Confirm that new variables have values in staging before production promotion.
- Check that client-exposed variables contain no private credentials.
- Review startup and deployment logs for missing-variable errors without printing values.
- Verify that the deployment uses the intended environment, project, account, and database.
Monthly or quarterly
- Remove variables belonging to retired features, services, or team members.
- Review who can read, create, edit, and deploy secrets in the hosting dashboard and CI/CD system.
- Check repository history, pull requests, issue attachments, build logs, and error tracking for accidental exposure.
- Confirm that backups and deployment exports do not contain unprotected secret values.
- Test whether an authorized operator can rotate a representative credential without an avoidable outage.
Use a CI/CD secret store or cloud secret manager when the platform supports one. Store only the values required by a job, scope credentials to specific projects or environments, and avoid passing production secrets to pull-request builds from unknown branches. A deployment log should identify the variable name or validation result, not the variable value.
For scheduled jobs, audit the variables separately from the web application. A cron-triggered task may run under a different service account or deployment context. The cron expression guide is useful when checking the schedule, while the secret review should confirm that the job has only the credentials it needs.
How to interpret changes
A changed value is not automatically a security incident. It may reflect a planned database migration, a new API endpoint, a framework convention, or a staging reset. Classify each change before taking action:
- Planned change: link the update to a ticket, release, owner, or maintenance record. Confirm the old value is no longer required.
- Configuration drift: investigate differences between environments, especially when staging works but production fails. Check names, whitespace, URL schemes, permissions, and whether the value was supplied at build time or runtime.
- Unexpected access or exposure: treat the credential as potentially compromised until its scope and usage are understood.
If a secret may have entered a repository, log, support ticket, screenshot, browser bundle, or CI/CD artifact, do not rely on deleting the visible copy. Preserve enough evidence to understand the exposure, then revoke or rotate the credential through its issuing service. Search for other copies, review recent access where available, update the deployment, and monitor for failures or unusual activity. Record what happened, which systems were affected, and which preventive control will change.
Rotate credentials in an order that keeps recovery possible: create or enable the replacement, add it to the protected store, deploy and verify, then revoke the old value. For keys used to sign sessions or tokens, plan for the effect on existing sessions and dependent services. Do not paste active credentials into a diagnostic tool or share them while asking for help. When inspecting API payloads, use a safe redaction workflow; the JSON formatter and validator guide includes practical guidance for debugging and sharing API data safely.
When to revisit
Revisit this article and your variable register at least monthly or quarterly, and immediately after a material change. Useful triggers include creating a new cloud environment, onboarding or offboarding a developer, changing hosting dashboards, adopting a new framework, adding a third-party integration, migrating a database, or changing CI/CD providers.
Also schedule a review after a framework or dependency update if it changes environment-variable naming, client-side exposure, build behavior, container startup, or secret-store integration. Hosting platforms regularly adjust dashboard terminology and deployment flows, so screenshots and internal runbooks should be checked after platform changes rather than trusted indefinitely.
Practical review checklist
- Export the current variable names, not their secret values, from each environment.
- Compare the list with the application’s documented requirements and recent code changes.
- Mark every item as public configuration, private configuration, credential, or cryptographic material.
- Verify separate values and least-privilege access for development, staging, and production.
- Inspect repositories, logs, CI/CD jobs, artifacts, browser bundles, and tickets for exposure.
- Rotate credentials that are expired, unused, over-permissioned, shared too broadly, or possibly leaked.
- Run a staging deployment, then a controlled production deployment, and confirm that logs redact sensitive values.
- Update the register with the owner, review date, rotation notes, and any new platform or framework behavior.
Environment variables are a delivery mechanism, not a complete secrets-management strategy. When the application grows, combine protected deployment settings with a dedicated secret store, access reviews, monitoring, backups, and a tested incident response process. This recurring review keeps cloud hosting changes understandable and makes one-click or automated deployments safer to repeat.