Cookies ahead

Our support chat tool "Intercom" would like to collect some more data on you. See the related link for more details.

Docs

ENV vars intro

Reviewedbyfl

Markdown ↓

🌱

Configure once, run across environments.

Environment variables let you manage configuration across different environments—database credentials, API keys, settings—without hard-coding secrets into your codebase.

Problem

When deploying the same application across multiple environments—development, staging, production—configuration must differ for database credentials, API keys, and environment-specific settings, yet you cannot hard-code these secrets into version-controlled files without compromising security. You most likely run at least two environments for your app: a local one for development and one on fortrabbit for production. Both instances probably have access to a database, but your local MySQL credentials differ from the remote ones, your config.php file is under Git version control, and team members need individualized local settings without affecting the shared codebase.

Solution

Store everything specific to the environment in environment variables, or 'ENV vars' for short. An ENV var is a key-value pair, like so: MY_SQL_PASS=sCRAmblEDegGGs. The concept of ENV vars is widely used across different software systems, including Apache, Node.js, and PHP. Accessing ENV vars from PHP is straightforward, and it is a commonly accepted best practice to use them for configuration management.

Benefits

  • Security: Store sensitive information like database credentials and API keys outside of your codebase. See ENV var security.
  • Portability: Code can run in different environments without modification. Allow each team member to have their own local settings without affecting the shared codebase.
  • Separation: Keep code and configuration apart.

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

AI use & editorial processEdit on GitHub ↗