Using ENV vars on fortrabbit
⚙️
Configure environment variables.
Manage environment variables with the fortrabbit dashboard.
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 it. For example, for Laravel and Craft, an ENV var like DB_PASSWORD will be populated with the password of the database. So, most likely, your fortrabbit environment will work out of the box. As a bonus you even 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. For example:
MY_MYSQL=${FORTRABBIT_MYSQL_PASSWORD} # MY_SQL is the key # ${FORTRABBIT_MYSQL_PASSWORD} is an alias for a value populated by fortrabbitapache
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 it's value by 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}apache
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=somethingapache
# 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}\ _\-\+=\.,:;\?!@~%&\*\(\)\[\]\{\}<>\/\\#]+$/uraw
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 Meshell
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