Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Tomasz_Kisiel's avatar

Can't use env on shared hosting.

In my env file I have variable:

APP_DOMAIN=example.com

Then in routes I want to use it in this way:

Route::domain( '{subdomain}' . env('APP_DOMAIN') )->group( function() { ... } );

When I use it on local everything work great, but when I deploy app on shared hosting env('APP_DOMAIN') return empty string. What's wrong ?

0 likes
2 replies
Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

Never use env outside of config files. Move it to a config file and use the config instead

In config/app.php

'domain' => env('APP_DOMAIN'), 
Route::domain( '{subdomain}' . config('app.domain'))->group( function() { ... } );
Tomasz_Kisiel's avatar

Thanks. It's work :D

Can you explain me why I shouldn't use env outside config files ?

Please or to participate in this conversation.