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

SergioGregorutti's avatar

Multiple sites sharing same files and different env variables

Hi,

I need a particular server configuration.

I need multiple sites sharing the same files, but with different databases and different environment variables. And I don´t know if this is possible with Forge and Digital Ocean.

To be clear, I need for example:

www.site1.com and www.site2.com using the same Laravel application, but connecting to different databases. And if I change a file inside the GIT repository I want just one deploy to the server and the changes on both sites.

Thanks in advance! :)

0 likes
8 replies
SergioGregorutti's avatar

Oh it was so simple!

I need also different images path dir, different api keys, etc.

But I think that I can do all of this checking the domain.

Thanks!!!

SergioGregorutti's avatar

@bashy How can I set different environment variables depending on the domain? I mean, where can I put the switch to say: "Ok, if the domain is site1.com the env vatiable 'database' is equal to 'base1'."

SergioGregorutti's avatar

Hmm... That's confusing.

I need to use for example "env('DB_DATABASE')" on "config/database.php" and change the value of env('DB_DATABASE') depending on the domain. Makes sense?

It's sounds really easy to do, but Its not. Hehe..

bashy's avatar

You can't change env() since they're loaded via PHP or the .env file at load but you can use the session or config?

# Accessing Configuration Values

You may easily access your configuration values using the Config facade:

$value = Config::get('app.timezone');
Config::set('app.timezone', 'America/Chicago');

You may also use the config helper function:

$value = config('app.timezone');

http://laravel.com/docs/5.0/configuration#accessing-configuration-values

SergioGregorutti's avatar

Awesome!

The last thing would be: Where I need to put the switch logic and set the variables to be available at "config/database.php" file for example? Something like "Hey, before anything set these variables depending on the domain".

Please or to participate in this conversation.