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

rvanbaalen's avatar

Running migrations for multi-server applications behind load balancer

I've been playing with setting up a load balancer in Forge and running multiple web servers (PHP nginx) behind it.

However, I ran into a theoretical issue.

Currently, my CI triggers the Forge Deployment URL with the secret token to start the code deployment on the server. Now that I have multiple servers, the deployment is running on each server.

However, the deploy script for the server also runs php artisan migrate.

In theory, with the multiserver setup, the migrations could run simultaneously on the same database server. How do I solve this properly? Is there a best practice? I was surprised I couldn't find much information about this subject, so either this is a niche issue or I'm overlooking something obvious.

0 likes
3 replies
martinbean's avatar

@rvanbaalen When deploying, you need to choose one of your available nodes to be the one to run migrations.

rvanbaalen's avatar

@martinbean Are there any best practices to do so? I was slightly surprised that Forge doesn't have such a feature baked in, since they also allow you to set up the whole load balancer etc.

rvanbaalen's avatar

In an unrelated note; the AI had an excellent answer, but as soon as a real human replied, the AI answer disappeared. Why? Can I find it somewhere? It had multiple solutions for my question.

Please or to participate in this conversation.