I have a few subdomain in my laravel 5 application, each sub domain have a specific configuration, like mail, nocaptcha, etc.
how to set .env file to work with my-specific subdomain ?
I have a few subdomain in my laravel 5 application, each sub domain have a specific configuration, like mail, nocaptcha, etc.
how to set .env file to work with my-specific subdomain ?
I had the same issue, Based on @Marcin's answer I built this one (Works with laravel 5.2.X)
I added in the bootstrap/app.php
after
$app = new Illuminate\Foundation\Application( realpath(__DIR__.'/../') );
I hope that helps someone
Greetings
The best solution I found is to use .htaccess plus env variables.
In .htaccess add these lines:
In bootstrap/app.php add after the app initialisation:
Create a new directory called "env" in your Laravel root and add your config files as:
(Of course you can keep it in your root as is currently, but for many subdomains it's better to move into a directory => looks much cleaner => everyone's happy! :) )
You can’t. Each subdomain will be running in the same environment.
If you want per-subdomain configuration then your best bet is to either create a configuration file in the config directory with each subdomain’s settings, or use a database approach.
Yes, you can use separate
.env
files for each subdomain so if you use env variables in your config it will work without great modifications.Create
bootstrap/env.php
file with the following content:Now modify
bootstrap/app.php
to load your customenv.php
file. Just add:after
Now you can create separate env files for each domains for example if you use
testing.app
,abc.testing.app
anddef.testing.app
you can have.env
file for main domain (and for all subdomains that don't have custom env files) and.abc.env
and.def.env
files for custom env variables your your subdomains.