Using ENV vars on fortrabbit

Published

Updated

⚙️

Configure environment variables.

Set the environment variables of a fortrabbit environment in the dashboard, in dotenv syntax. Reference system ENV vars for database and other credentials, and use Base64 for values with special characters.

The editor takes dotenv syntax, one KEY=value per line, so several variables can be added or changed at once. Saving replaces the whole set: a line removed from the editor removes that variable.

ENV var types on fortrabbit

An environment gets ENV vars from three sources. All of them are available to the app at runtime.

Software template ENV vars

The detected or chosen software seeds ENV vars in the names it expects. For Laravel and Craft CMS, DB_PASSWORD references the database password, so the environment works without further configuration, and a reset of the database password needs no change.

System ENV vars

fortrabbit fills the system ENV vars with the access details of the platform services and keeps them up to date. Every environment gets these:

NameHoldsSet by
FORTRABBIT_DB_HOSTHost name of the environment's MySQL server.The service, when it is provisioned
FORTRABBIT_DB_PORTPort the MySQL server listens on.The service, when it is provisioned
FORTRABBIT_DB_NAMEName of the environment's database.The service, when it is provisioned
FORTRABBIT_DB_USERUser the environment connects to MySQL with.The service, when it is provisioned
FORTRABBIT_DB_PASSWORDPassword for that user. Held encrypted and left out of every API response.The service, when it is provisioned
FORTRABBIT_MAIN_DOMAINThe environment's main domain, without a scheme.The environment it belongs to
FORTRABBIT_ENVIRONMENTThe environment's public id, such as en-abc123.The environment it belongs to
FORTRABBIT_ENVIRONMENT_NAMEThe environment's name, as it reads in the dashboard.The environment it belongs to

Reference a system ENV var from a custom one instead of copying its value, so a rotated password keeps working:

MY_DB_PASSWORD=${FORTRABBIT_DB_PASSWORD}
# MY_DB_PASSWORD is the key
# ${FORTRABBIT_DB_PASSWORD} is an alias for a value populated by fortrabbit
apache

System ENV vars never overwrite an ENV var created by hand.

Custom ENV vars

The ones added in the dashboard. A custom ENV var can reference another one that holds a value:

# will work:
OTHER_VAR=something
MY_VAR=${OTHER_VAR}
apache

Define a variable before referencing it. A reference to a variable that itself holds a reference does not resolve:

# will not work:
MY_VAR=${OTHER_VAR}
OTHER_VAR=${ANOTHER_VAR}
ANOTHER_VAR=something
apache

ENV var validation

The dashboard checks every line on save:

  • Names use letters, digits and underscores, up to 128 characters.
  • Values hold up to 8,192 characters: letters, digits, spaces and these characters: _ - + = . , : ; ? " ! @ ~ % & * ( ) [ ] { } < > / \ # ^
  • A $ is only allowed as part of a ${…} reference.
  • An environment holds up to 200 ENV vars.

A value outside these rules, such as an API key with a $ in it, fails with an error. Encode it with Base64.

Base64 encoding and decoding

The Base64 helper next to the editor encodes a value and adds the fr+base64: prefix. The platform decodes it at runtime, so the app receives the original value. Use it for special characters, multi-line values and binary data.

# Can NOT save this due to special characters
MOTTO=$$$$ Rules Everything Around Me

# The tool converts it to Base64 with a prefix
MOTTO=fr+base64:JCQkJCBSdWxlcyBFdmVyeXRoaW5nIEFyb3VuZCBNZQ==

# The environment receives the original value
MOTTO=$$$$ Rules Everything Around Me
shell

Laravel and Symfony decode values with a base64: prefix themselves. The fr+base64: prefix works for any app. Base64 is an encoding, not encryption: see ENV vars and security.

Reserved ENV var names

These names are taken by the platform, the shell or PHP's $_SERVER. A name ending in * stands for every name with that prefix.

__FRBIT*, FORTRABBIT*, HTTP_*, LC_*,
_, argc, argv, AUTH_TYPE, BASH_ENV, CHARSET, CONTEXT_DOCUMENT_ROOT, CONTEXT_PREFIX,
DOCUMENT_ROOT, FCGI_ROLE, GATEWAY_INTERFACE, GROUP, HOME, HTTPS, INPUTRC, LANG,
LD_AUDIT, LD_LIBRARY_PATH, LD_PRELOAD, LOGNAME, MAIL, MUSL_LOCPATH, OLDPWD,
ORIG_PATH_INFO, PAGER, PATH, PATH_INFO, PATH_TRANSLATED, PHP_AUTH_DIGEST, PHP_AUTH_PW,
PHP_AUTH_USER, PHP_SELF, PROMPT_COMMAND, PS0, PS1, PS2, PS3, PS4, PWD, QUERY_STRING,
RANDOM, REDIRECT_REMOTE_USER, REMOTE_ADDR, REMOTE_HOST, REMOTE_PORT, REMOTE_USER,
REQUEST_METHOD, REQUEST_SCHEME, REQUEST_TIME, REQUEST_TIME_FLOAT, REQUEST_URI,
SCRIPT_FILENAME, SCRIPT_NAME, SCRIPT_URI, SCRIPT_URL, SERVER_ADDR, SERVER_ADMIN,
SERVER_NAME, SERVER_PORT, SERVER_PROTOCOL, SERVER_SIGNATURE, SERVER_SOFTWARE, SHELL,
SHLVL, SSH_CLIENT, SSH_CONNECTION, SSH_TTY, TERM, USER
raw

Frequently asked

How do I store a value with a $ sign in an ENV var on fortrabbit?

Encode it with the Base64 helper next to the ENV var editor in the dashboard. The value gets the fr+base64 prefix, and the app receives the decoded original.

#

Written by humans and AI in collaboration.

AI use & editorial processEdit on GitHub ↗