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

mhdev's avatar
Level 1

Ideal Server Set-up for two subdomains and shared database

I've got a Laravel project that I'm currently hosting on Digital Ocean, with Laravel Forge. Fairly new to Forge, and server architecture generally, so would appreciate some advice on the best way to do this.

I've got a Laravel 11 project with PHP 8.3. I've got two subdomains - subdomain1.example.com & subdomain2.example.com, and it's a monolithic repo so the code for both is within one repository. The two subdomains also share a MariaDB database.

How would I go about setting this up within Forge? Ideally I'd have two separate servers, one for each subdomain, so that if one server goes down the other is still accessible. So is it possible to set up my subdomains on separate servers (point the relevant A records at each), and then point each of the servers at the shared database (which I guess will need to sit on one of the servers?) via the .env? Or is it best to have just a single server with both subdomains on there as separate sites?

In terms of deployments, I will want to deploy off of my main branch to both subdomains. Will this cause issues? I'm thinking with my migrations, I don't want them to be run multiple times by the deployment scripts on the separate servers/sites.

Appreciate the help

0 likes
2 replies
martinbean's avatar

@mhdev Why do you have one codebase, but deploy them to two subdomains? Is it the same app deployed to both sub-domains? Or does the app just handle routing for two apps using two route groups, i.e.

Route::domain('subdomain1.example.com')->group(function () {
    // Subdomain 1 routes...
});

Route::domain('subdomain2.example.com')->group(function () {
    // Subdomain 2 routes...
});

Regardless, if you do deploy the application to two separate servers, then you want the database running in the same network to avoid latency. Otherwise, if you host one subdomain on a completely different server and it has to connect to the database over a network, then you may find connections and queries slower than you’d like.

When it comes to deployment, if you are deploying to two separate “sites” then this is going to cause complications as well. You need to nominate one server as the one to run commands such as migrations, but then you also need to a way to halt the deployment of both apps if say, migrations fails. You don‘t want to get in a situation where you deploy the app to subdomain 1, then try and run the migrations, migrations fail, and now you’re left in a weird, inconsistent state where the new code has been deployed to one server (and expecting tables/column that don’t exist because the migrations failed), whilst subdomain 2 still has the old code.

So, my advice is not to over-complicate things if you don‘t need to. Otherwise you just start to introduce more problems than you’re solving.

mhdev's avatar
Level 1

Thanks @martinbean - yes it's two route groups as per your code snippet. Really good feedback, thanks. Definitely feels like having one server and one site within that server is the way to go and not to overcomplicate it. Would you recommend putting my database on a separate, dedicated server or having it all within the app server?

Please or to participate in this conversation.