Skip to content
Server and cPanel3 min read

.env file not read after uploading your project to hosting

process.env.DATABASE_URL is undefined (or env() returns null) only on the server

Short answer

If .env values are empty on the server, either the file is not really there (Git does not deploy it, File Manager hides it, Windows may save it as .env.txt) or the app does not read it: Laravel ignores it after config:cache, Node.js only reads .env through dotenv or --env-file, and Vite and React variables are baked in at build time on your computer. For Node and Python apps on cPanel you can set variables in the app's own screen instead.

ArabyHost teamLast updated: ShareWhatsAppXLinkedIn
Contents
  1. Check first: is the file really there?
  2. Causes by project type
  3. Protect the file
  4. How to confirm it is fixed
  5. On ArabyHost

On your computer the project reads its database URL and API key from .env; on the server the value is undefined or null, so the database connection fails or you get a missing-key error. Environment variables do not travel with the code on their own, and each language reads them differently.

Check first: is the file really there?

Open File Manager, enable Show Hidden Files under Settings, and look in the project root:

  • No .env: files starting with a dot are hidden, and .env is in .gitignore in most projects, so Git never delivers it. Create it with + File and paste in your values, or copy .env.example and edit it.
  • A .env.txt or env: your Windows editor added an extension or dropped the dot. Rename it to exactly .env.
  • In another folder: in Laravel it belongs in the project root next to artisan, not inside public.

Check the format too: KEY=value with no spaces around =, and quotes around values containing spaces or #.

Causes by project type

1. Node.js does not read .env by itself

Node.js does not load .env automatically; locally, a script or dev tool was probably doing it for you. Options:

// First line of your startup file, after npm install dotenv
require('dotenv').config({ path: __dirname + '/.env' });

Or, on Node.js 20.6 and later, node --env-file=.env app.js. The __dirname path matters, because the working directory under Passenger may not be your project folder.

The clearest way on cPanel: open Setup Node.js App, select your app, add each variable under Environment variables, then Save and Restart. Those values reach process.env with no library. Python apps in Setup Python App have the same section, or use python-dotenv. See the environment variables on hosting guide.

2. Laravel’s config cache

After php artisan config:cache, Laravel reads settings from bootstrap/cache/config.php and ignores .env completely. If you uploaded that file from your computer, your computer’s values are in use. Clear it:

php artisan config:clear

Or delete bootstrap/cache/config.php in File Manager. Remember that env() should only be called inside config/ files; elsewhere use config('services.x.key'), or it returns null once config is cached. If APP_KEY is empty, see No application encryption key.

3. Vite, React and Next.js: variables are baked in at build time

Frontend apps have no server reading .env after upload: values are copied into the JavaScript at npm run build. So:

  • Names must start with VITE_ in Vite, REACT_APP_ in Create React App, and NEXT_PUBLIC_ for anything the browser needs in Next.js.
  • .env.production or .env must exist on the machine that runs the build.
  • Any change needs a rebuild and a new upload.

An empty value here is a common cause of a blank page after deploy.

4. Plain PHP

PHP only reads .env through a library such as vlucas/phpdotenv. Check that the code loads it with a correct path, such as Dotenv\Dotenv::createImmutable(__DIR__)->load();, and that vendor was uploaded.

5. The app was not restarted

Node and Python apps read variables only at startup. After any change click Restart in Setup Node.js App or Setup Python App, or create tmp/restart.txt inside the app folder so Passenger restarts it.

Protect the file

If .env sits inside a public folder, add to the .htaccess next to it:

RewriteEngine On
RewriteRule (^|/)\.env$ - [F,L]

Then open example.com/.env: you should get a 403.

How to confirm it is fixed

Temporarily log whether the variable exists, not its value, for example console.log(!!process.env.DATABASE_URL), then remove the line. In Laravel, run php artisan about to see the current environment.

On ArabyHost

On AI/Developer plans you set environment variables for Node.js and Python apps in Setup Node.js App and Setup Python App, which run through Phusion Passenger, and you run artisan over SSH. On every plan you create and edit .env in File Manager once hidden files are shown. If the error persists, the Araby AI assistant reads the error log and tells you which variable is missing.

FAQ

Should I push .env to GitHub?

No. It holds passwords and API keys, and anyone who can read the repository could use them. Commit a .env.example with variable names only, and create .env on the server by hand.

Can someone read my .env from the browser?

Yes, if it sits inside the public web folder. In Laravel, point the domain at public so .env stays outside it; in other projects, keep .env outside public_html or block it in .htaccess.

I changed a value in .env and nothing happened. Why?

Apps read the file when they start. Restart the Node or Python app from its screen, clear the config cache in Laravel, and rebuild and re-upload Vite and React apps.

Are API keys in VITE_ variables secret?

No. Anything starting with VITE_, REACT_APP_ or NEXT_PUBLIC_ is written into the JavaScript files and visible to any visitor. Keep secret keys on the server only.

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.