Set environment variables
Add or change the environment variables of an app and apply them.
Each app has its own environment variables. This guide adds and changes them after the first deploy. A saved change takes effect with the next deploy of the app. Environment Variables explains detection, secrets and generations.
Before you start
- A deployed app. The examples use the app
copperfox.
Steps
Add or change variables
- Open the app and select the Environment tab.
- Edit Key and Value in the table, or select Bulk edit and paste one variable per line. Keys and values are separated by
=. Lines that start with#are ignored. - Save. All changes are saved together. If one variable is invalid, nothing is saved and the errors are listed.
lly env copperfox set LOG_LEVEL=debug FEATURE_X=onTo load a whole .env file:
lly env copperfox push .env.productionApply the change
The running app keeps the values it was started with. Redeploy it to apply the new ones.
After saving, the console confirms that the variables apply on the next deployment and offers Redeploy. The Environment tab shows whether the saved values are live or wait for the next deploy.
lly redeploy copperfoxCheck that it worked
lly env copperfox Environment Variables
Key Value
LOG_LEVEL debug
API_TOKEN •••••• · src/api.tsSecret values are masked. Detected variables show the file they were found in.
Secrets
A variable is treated as a secret if its name contains SECRET, PASSWORD, TOKEN, KEY, CREDENTIAL or PRIVATE, or if it is a database URL. A secret value is not shown again after saving. To change a secret, remove it and add it again:
lly env copperfox unset API_TOKEN
lly env copperfox set API_TOKEN=<new value>
lly redeploy copperfoxIf it does not work
| What you see | Cause | Fix |
|---|---|---|
| The app still uses the old value | The change is saved but not applied | Redeploy the app |
lly env set exits with code 2 | The variable is an existing secret | unset it, then set it again |
lly env get exits with code 2 | The variable is a secret | Secret values cannot be read |
Exit code 4 | The variable does not exist | Check the name with lly env copperfox |
Your app does not find PORT | LILY does not set PORT | Set the port the app listens on as a service port. See Expose a port |
More messages and their fixes: Troubleshooting.
Use an agent
Set these environment variables on my LILY app "copperfox": LOG_LEVEL=debug.
Run `lly env copperfox set LOG_LEVEL=debug`, then `lly redeploy copperfox`.
Never print secret values. If a variable is an existing secret, tell me instead of changing it.