Configure Grav with environment variables

Published

Updated

Reviewedbyfl

Grav 2 reads configuration overrides from ENV vars once GRAV_CONFIG is on, which the Grav software template sets on fortrabbit. Config per domain keeps debugging on locally and off in production.

Configuration through ENV vars

Grav 2 reads a .env file at the project root and accepts configuration overrides from real environment variables, such as the ENV vars of a fortrabbit environment. Set GRAV_CONFIG to switch the feature on, then map any config path to a variable name by replacing the dots with double underscores:

GRAV_CONFIG=true
GRAV_CONFIG__system__cache__enabled=true
GRAV_CONFIG__plugins__email__mailer__smtp__password=secret
raw

The software preset sets two of these already. GRAV_CONFIG is on, and GRAV_CONFIG__system__errors__display is 0, because the shipped user/config/system.yaml turns full backtraces on and that file is not replaced by deployments.

Server-set variables win over anything in a .env file, so secrets belong in the dashboard rather than in the repo. The shipped .env.example documents the remaining options, including the GRAV_CONFIG_ALIAS__ prefix for plugin slugs containing a hyphen.

Environment configuration by domain

Grav also reads configuration per domain. For a site under development locally, debugging is usually wanted there and unwanted on fortrabbit. Create a system.yaml for the custom domain, for www.my-grav.tld that is user/www.my-grav.tld/config/system.yaml:

debugger:
  enabled: false
yml

The stricter approach sets user/config/system.yaml as restrictive as possible and keeps a localhost override in user/localhost/config/system.yaml:

debugger:
  enabled: true
yml

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

AI use & editorial processEdit on GitHub ↗