Contents
Environment variables are the values that differ between your computer and the server and must not live in the code: the database password, API keys, the site URL, the run mode. Locally you usually keep them in a .env file. On hosting there’s no single place for them: each kind of project reads them from somewhere different, which is behind most “works on my machine, not on the server” problems.
Where your project reads its variables
| Project type | Where values come from on hosting | When they’re read |
|---|---|---|
| Laravel and PHP | A .env file in the app folder, outside public_html |
On each request, or once at config:cache |
| Node.js (Setup Node.js App) | The app’s Environment variables section, or .env with dotenv |
When the app starts |
| Python (Setup Python App) | Environment variables, or .env with python-dotenv |
When the app starts |
| React, Vue, Vite front end | .env.production on your computer |
At build time only |
| A script run by cron | Nothing automatic; the script loads .env itself |
On every run |
Steps
1. List the variables you need
Open .env.example in your project, or search the code for process.env., env( and os.environ, and write down the names. If an AI tool built the project, ask it: “List every environment variable this project needs.”
2. Prepare production values
Don’t copy your local values as they are. On the server these usually change: the database name and user (with the cPanel account prefix), APP_URL to https:// and your domain, the run mode to production, and secret keys, which are best generated fresh with the password generator.
3. Laravel and PHP: the .env file
- In File Manager, open Settings and enable Show Hidden Files (dotfiles).
- Go to the app folder (such as
/home/USER/myapp, notpublic_html). - Copy
.env.exampleto.env, open it with Edit and change the values. - Under Permissions, set the file to
600so only your account can read it.
If a simple PHP project forces you to keep .env inside public_html, block browser access with this in .htaccess:
<Files ".env">
Require all denied
</Files>
Then open https://example.com/.env and confirm it returns 403. The full Laravel walkthrough is in the Laravel deploy guide.
4. Node.js and Python: the Environment variables screen
In Setup Node.js App or Setup Python App, click the edit icon next to the app, then under Environment variables click Add Variable, enter the Name and Value, click Done, and when all are added click Save and then Restart. The code reads them directly:
const db = process.env.DATABASE_URL;
import os
db = os.environ["DATABASE_URL"]
A .env file with dotenv is fine too, but give its full path, because the working directory under Passenger may not be your project folder:
require('dotenv').config({ path: '/home/USER/api/.env' });
from dotenv import load_dotenv
load_dotenv("/home/USER/app/.env")
More in the Node.js app guide.
5. Front end: build-time variables
Vite variables starting with VITE_ and Next.js variables starting with NEXT_PUBLIC_ are written into the JavaScript files during npm run build. So they go in .env.production on your computer before the build, and any change needs a new build and upload. Everything in them is visible to every visitor, so never put a secret key there. Next.js variables read only on the server go in the Environment variables screen like any Node.js app.
6. Cron jobs and background scripts
A cron job sees neither Passenger’s variables nor .bashrc. Load the file inside the command itself:
cd /home/USER/app && set -a && . ./.env && set +a && venv/bin/python worker.py
7. Check without exposing secrets
Print which variables are set, never their values. In Node.js, add this line temporarily at the top of the startup file, restart, and open the Passenger log:
['DATABASE_URL', 'JWT_SECRET'].forEach(k => console.log(k, process.env[k] ? 'set' : 'MISSING'));
Check from inside the app rather than from an SSH prompt, because the shell doesn’t necessarily see the values Passenger passes to the app. And never leave a page showing phpinfo() or all variables on a live site.
Common syntax mistakes
- Spaces around
=: writeDB_PASSWORD=abc, notDB_PASSWORD = abc. - A value with a space or
#: wrap it in quotes:APP_NAME="My Shop". - A file saved with Windows line endings: the password becomes
abc\rand the database login fails. Save the file asLF(the option is at the bottom of the VS Code window). - A different letter case:
Db_Hostis notDB_HOST; names are case-sensitive.
Troubleshooting
- The app says a variable is undefined: see .env not loaded.
- Everything works locally only: server values still point at
localhost:3000or your local database. See works locally, not on the server. Access denied for user: the username lacks its prefix or the password is wrong. See connect your app to the database.- You pushed
.envto GitHub by mistake: change every secret right away, then follow push a project to GitHub.
On ArabyHost
On every ArabyHost plan you create the .env file for PHP and Laravel projects in File Manager, and your account stays isolated from other accounts inside CloudLinux CageFS. On the AI/Developer plans you set variables for Node.js and Python apps in Setup Node.js App and Setup Python App, or over SSH. If the app doesn’t pick up a value, the Araby AI assistant in the panel reads the error log and explains why. To choose a plan, see the developers page.
FAQ
Should I push my .env file to GitHub?
No. Add it to .gitignore and commit a .env.example with the variable names and no values instead. Then create the .env file or the variables on the server by hand.
Why can't I see .env in File Manager?
Files whose names start with a dot are hidden by default. Open Settings at the top of File Manager and enable Show Hidden Files (dotfiles).
I edited .env and nothing changed. Why?
The app is still running with the old values. In Laravel clear the config cache (config:clear) or delete bootstrap/cache/config.php; in Node.js and Python click Restart on the app's page. Front-end variables need a new build.
Do cron jobs see the Setup Node.js App variables?
No. Variables on that screen are given only to the app Passenger runs. A script started by a cron job has to load the .env file itself.