ENV vars intro

Published

Updated

🌱

Configure once, run across environments.

Environment variables hold the configuration that differs between environments, such as database credentials and API keys, so the code in git stays the same everywhere.

Why ENV vars

An app runs in at least two places: a local development environment and an environment on fortrabbit. Both have a database, with different credentials. The config files are in git, shared with the team, and must not contain the production password.

ENV vars solve this. An ENV var is a key-value pair, such as DB_PASSWORD=sCRAmblEDegGGs, set outside the code. The code reads the key, and each environment supplies its own value.

  • Security: secrets stay out of the repository, see ENV var security.
  • Portability: the same code runs locally, on staging and in production.
  • Team work: each developer keeps their own local values.

ENV vars on fortrabbit

Locally, a .env file holds the values. On fortrabbit, set them in the ENV vars settings of the environment. To read them in code, see read environment variables in PHP.

Written by a human. Review, grammar checks and typo fixes by AI.

AI use & editorial processEdit on GitHub ↗