Skip to content
Development and deployment2 min read

What are environment variables?

Short answer

Environment variables are name=value settings an application reads from the operating system when it starts, instead of having them written into the code. They hold settings that differ between your computer and the server, and secrets such as passwords and API keys, often kept in a .env file.

ArabyHost teamLast updated: ShareWhatsAppXLinkedIn
Contents
  1. How they work
  2. Example: a .env file and how to read it
  3. Common mistakes
  4. On ArabyHost

The rule in modern apps: the same code runs everywhere, and configuration comes from the environment. That’s how your laptop uses a test database and the server uses production, without changing a single line of code.

How they work

Every program inherits a list of variables from the process that started it, such as PATH and HOME. You can add your own before launching:

export APP_ENV=production
node server.js

Typing them every time gets old, so libraries such as dotenv read a .env file and load its contents into the environment at startup. Since Node.js 20.6 you can skip the library with node --env-file=.env server.js.

Example: a .env file and how to read it

APP_ENV=production
DB_HOST=localhost
DB_NAME=user_shop
DB_PASSWORD=change-me
MAIL_API_KEY=replace-with-real-key
Language How to read it
Node.js process.env.DB_PASSWORD
Python os.environ.get("DB_PASSWORD")
PHP $_ENV['DB_PASSWORD'] or getenv('DB_PASSWORD'), depending on the loader
Laravel env('DB_PASSWORD'), only inside config/ files

Common mistakes

  • Committing .env to Git: add it to .gitignore and keep a .env.example without real values. If it slips in, rotate every secret it contained.
  • .env inside the public folder: in Laravel the domain must point at public so the file stays out of visitors’ reach.
  • Front-end variables aren’t secret: anything prefixed VITE_ or NEXT_PUBLIC_ is baked into the JavaScript the browser downloads, so never put API keys there.
  • Spaces and quotes: KEY = value with spaces may not parse the way you expect; write KEY=value.

On ArabyHost

On AI/Developer plans, cPanel’s Setup Node.js App and Setup Python App each have a section for adding environment variables per app, then restart the app to apply them. You can also keep a .env file in the app folder outside public_html and set its permissions to 600 so only your account can read it. Your account is isolated inside CageFS, so other users on the server can’t see your files. For Python apps, see also virtual environments.

FAQ

Is a .env file safe?

Yes, as long as it sits outside the site's public folder and never goes into Git. Inside public_html without protection, any visitor might download it and read your passwords.

Why doesn't anything change after I edit a variable?

Apps read environment variables only at startup. Restart the app, and in Laravel clear the config cache with php artisan config:clear.

What is .env.example for?

It lists the variable names the app needs with dummy values. It's committed to Git so any new developer or server knows what to set without exposing real values.

Useful? Share it with someone who needs it:WhatsAppXLinkedIn

Read next

Ready to put your idea online?

Fast, isolated hosting, support that understands you, and an AI assistant that fixes problems with you.