Running a 1-Click App? Use
instapods env set - it writes to the app’s own config file and restarts the app automatically. The .env-in-app-directory approach below is for custom-code pods (Static, PHP, Node.js, Python).Setting Environment Variables
Option 1: The instapods env command (Recommended)
Set one or more variables straight from the CLI:
--show-values):
.env file - run instapods pods reload afterward to restart. For 1-Click Apps it targets the app’s own config file and restarts the app for you.
Option 2: Create a .env File
The manual approach — create a .env file in your app directory via the CLI:
Option 3: Set at Pod Creation (API)
Pass environment variables when creating a pod via the API:/etc/environment and automatically available to all processes.
How Each Preset Reads Environment Variables
Node.js
The systemd service setsNODE_ENV=production by default. Variables from /etc/environment are inherited automatically.
For .env files, use the dotenv package:
Python
Variables from/etc/environment are inherited by the systemd service automatically.
For .env files, use python-dotenv:
PHP
PHP-FPM provides access to system environment variables viagetenv(). For .env files, parse them manually or use a library:
.env files automatically — just create the file and it works.
Static
Static sites don’t run server-side code. For JavaScript apps that need configuration, use aconfig.js file:
Common Pattern: Database Credentials
After installing a database service, get the credentials and set them as env vars:Updating Variables
To update environment variables after pod creation:Best Practices
- Never commit secrets to git — always use
.envfiles or environment variables - Use defaults in code — Always provide fallback values (
process.env.PORT || 3000) - Reload after changes — Run
instapods pods reloadafter updating.envto restart the app - Separate configs — Use different
.envfiles for development vs production