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

phpMick's avatar
Level 15

Database migrations and deploying to a to load-balanced group.

Not really a Laravel question but this does seem to be the most helpful forum in the internet.

We am moving from a monolithic to a load-balanced architecture.

Previously when deploying code, I used to SSH onto our production box, do a git pull and then run any migrations.

How can I do this when I have more than one server,? I will be using an auto-scaled group in AWS and will use a script to pull the latest code, when the box is started. Where should I be running my migrations? I can't run them when the code is pulled because this will happen on each box.

Mick

0 likes
6 replies
squibby's avatar

Can you not just SSH into 1 machine and run the migrations from there. Thats what I do, running load balanced EC2 and a separate multi-AZ RDS for the database.

phpMick's avatar
Level 15

Hey @squibby

Sounds like you are doing pretty much what I want to do.

I was hoping to never SSH in to any box.

How do you get your application code onto you boxes?

I was just thinking, maybe it does not matter if every EC2 instance does a migrate, if it has already been done, it will just fail with "nothing to migrate"

Mick

squibby's avatar

I use Laravel forge to install app code on to each server which is linked to Github repo. I then SSH into one of them, and run the initial migrations and seeds which sets up my database in RDS. I like to check everything is all working.

I highly recommend using Laravel forge. It will you a lot of time in getting everything set up. On each code deployment from forge you can trigger post deployment command, php artisan migrate can be one of them, or you can remove it depending on the server.

I generally do all the setup on 1 machine and then move onto the other. I get all the Elastic load balancer in AWS (not in forge) working first though before I install all the app code.

You probably don't need to SSH to any server if you let Forge handle everything, but you can add keys in forge which makes access easy with forge user.

If you use Laravel forge to provision your load balancer on an EC2 things would become even easier for you. I prefer to keep that separate though, as I found I couldn't load balance servers in different availability zones which was what I wanted for high availability.

phpMick's avatar
Level 15

I don't have the option of using Forge, all of this has to be done using AWS tools.

csb's avatar

Hi Mick, just wondering if you figured out a solution to this using aws? @phpmick

Drfraker's avatar

I use laravel envoyer. It can run deployment hooks on specific servers. So you can create a deployment hook that runs the command php artisan:migrate one of your servers that is sitting behind your load balancer. I'm sure you could script this behavior manually in your deployment scripts.

Please or to participate in this conversation.