DEV Community

Bokor Attila
Bokor Attila

Posted on • Originally published at bokor.dev on

Automating Laravel Sail Setup: From Tedious to Trivial

Laravel Sail setup: from 15 minutes of tedious work to 30 seconds with one command. Here's how I did it.

I use Laravel Sail for my local development, but for every project I have the same setup with small changes so I don't get port conflicts. After doing this process countless times, I decided to automate it.

The Manual Process (The Old Way)

Setting up a new Laravel project locally used to involve these steps:

  1. Clone the existing project
  2. Copy the .env.example into .env file
  3. Set the DB_* access environment variables to the standard Sail ones
  4. Check my notes to see the last port number I used
  5. Set the APP_PORT to the next one (for example, 8057)
  6. Set all the other ports to follow the same logic, so I know when I want to connect to MySQL the port should be 3357 for the current project, etc.

Here's an example of my port configuration:

APP_PORT=8057
FORWARD_DB_PORT=3357
FORWARD_REDIS_PORT=6357
FORWARD_MEILISEARCH_PORT=7757
FORWARD_MAILPIT_DASHBOARD_PORT=18157
FORWARD_MAILPIT_PORT=1057
VITE_PORT=5157

SAIL_XDEBUG_MODE=develop,debug,coverage
Enter fullscreen mode Exit fullscreen mode

As you can see, I keep the last two digits consistent (57 in this case) across all ports, making them easy to remember and avoid conflicts.

  1. Since there is no vendor folder yet, and my local PHP usually differs from the project needs, I run the official Laravel Docker composer install:
docker run --rm \
    -u "$(id -u):$(id -g)" \
    -v "$(pwd):/var/www/html" \
    -w /var/www/html \
    laravelsail/php84-composer:latest \
    composer install --ignore-platform-reqs
Enter fullscreen mode Exit fullscreen mode

I created an alias for this: sailinit 84 (this runs composer install with PHP 8.4 in the current folder)

  1. When the dependencies install, I run sail up -d (I also made an alias for this: sup)
  2. Done! The project is locally working.

You can see that this is really boring, especially if you have to set up a new Laravel project locally like once a week.

The Solution: Automation

After a while, I was looking up more and more ways to create aliases to automate parts of this setup. I was also experimenting with small Go scripts (nothing fancy, I was only starting to learn).

After experimenting with Go a bit before, I knew that a Go program would definitely be perfect for this. The problem is that I was only just starting to learn Go. But that's where Google's Antigravity IDE came in handy. (I know Claude Code is probably better for this kind of stuff, but I just got 6 months of Google AI Pro free with my new phone and I'm going to squeeze every drop of value out of that subscription!) I started tinkering, and after about 2 hours of experimentation, I had a working program that automates this whole setup.

The New Flow

Now the process is incredibly simple:

  1. Clone the existing project
  2. cd into the project directory
  3. Run sailinit
  4. Done!

Conclusion: The Power of Vibecoding

I think vibecoding is really good for these kind of projects that have no real consequences. If it messes up something, it will be annoying, but nothing would happen with live projects or something only I will be annoyed to go back to manually setting up a project. :)

The time saved adds up quickly, and the mental overhead of remembering port numbers and manual steps is completely gone. Sometimes the best solutions come from scratching your own itch.

The Downside of Vibecoding

Of course, there's a catch. Now I have this setup written in Go, and I'm not actually that good at Go development. If I need to modify something, I'll have to either learn Go properly or "vibecode" my way through it. The thing is, I wouldn't normally "vibecode" in a way where I don't fully understand what's happening but for throwaway tools like this? It's acceptable in my opinion.

Want to try it yourself? Check out the repository: Sailinit on GitHub

Top comments (0)