Using ENV vars on fortrabbit
Updated
Reviewedbyfl
⚙️
Configure environment variables.
Set and manage environment variables on fortrabbit via the dashboard; supports dotenv format with Base64 encoding for special characters.
The input supports the dotenv file format and allows you to create or update multiple variables at once. The changes will be distributed after you save the page. That may take around 60 seconds.
ENV var types on fortrabbit
There are four different kinds of ENV vars here on fortrabbit which are available to your environment at runtime.
Software template ENV vars
Depending on the detected or chosen software, additional ENV vars will be seeded for you. This selection will configure the server ENV vars in ways the software can work with. For example, for Laravel and Craft, an ENV var like DB_PASSWORD will be populated with the database password. Most likely, the environment will work out of the box. You can also reset the database password without touching any configurations.
System ENV vars
System ENV vars are automatically updated values that contain access details for services offered by fortrabbit. These are the ones every environment gets:
| Name | Holds | Set by |
|---|---|---|
FORTRABBIT_DB_HOST | Host name of the environment's MySQL server. | The service, when it is provisioned |
FORTRABBIT_DB_PORT | Port the MySQL server listens on. | The service, when it is provisioned |
FORTRABBIT_DB_NAME | Name of the environment's database. | The service, when it is provisioned |
FORTRABBIT_DB_USER | User the environment connects to MySQL with. | The service, when it is provisioned |
FORTRABBIT_DB_PASSWORD | Password for that user. Held encrypted and left out of every API response. | The service, when it is provisioned |
FORTRABBIT_MAIN_DOMAIN | The environment's main domain, without a scheme. | The environment it belongs to |
FORTRABBIT_ENVIRONMENT | The environment's public id, such as en-abc123. | The environment it belongs to |
FORTRABBIT_ENVIRONMENT_NAME | The environment's name, as it reads in the dashboard. | The environment it belongs to |
Reference one from a custom ENV var rather than 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
System ENV vars will not overwrite existing, manually created ENV vars. This means: if you manually create an ENV var, we guarantee that we won't replace its value with a dynamically generated ENV var.
Custom ENV vars
Those are the ones you add yourself in the dashboard.
Nested ENV vars
You can use simple, nested variables in your custom ENV vars. Simple means, that you can set variables which reference other variables, which contain a value, for example:
# will work:
OTHER_VAR=something
MY_VAR=${OTHER_VAR}
Order matters. First define something before referencing. Multiple levels of interpolation are not supported. That means that you cannot use variables, which reference other variables, which again reference other variables, for example:
# will not work:
MY_VAR=${OTHER_VAR}
OTHER_VAR=${ANOTHER_VAR}
ANOTHER_VAR=something
ENV var validation
Strict validation rules for ENV vars are in use in the dashboard while entering. Chars like the "$" sign can be harmful in Linux systems. Here is the regex we use to validate the ENV var input in the dashboard:
/^[\p{L}\p{N}\ _\-\+=\.,:;\?!@~%&\*\(\)\[\]\{\}<>\/\\#]+$/u
So sometimes, when you want to store an external API key as an ENV var, you might get a validation error like: "Variable value contains invalid characters".
Base64 encoding and decoding
Use the Base64 helper in the dashboard to handle special characters, multi-line values, or long strings.
# 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
The tool encodes your value to Base64 and adds the fr+base64: prefix. This encoded value is stored safely. At runtime, the platform automatically decodes it, so your application receives the original value without any extra work.
Laravel and Symfony have similar built-in functionality for variables prefixed with base64:. If you use that, the framework handles the decoding. The fr+base64: prefix is a platform-level feature that works for any application, regardless of the framework.
Reserved environment variable names
There are some names you can not use here:
, __FRBIT__, argc, argv, AUTHTYPE, CHARSET, CONTEXT_DOCUMENT_ROOT, CONTEXT_PREFIX, DOCUMENT_ROOT, FCGI_ROLE, FORTRABBIT, GATEWAYINTERFACE, GROUP, HOME, HTTP_, HTTPS, LANG, LC__, 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, PS0, PS1, PS2, PS3, PS4, PWD, QUERY_STRING, 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