14 May 2026

How I Run Many Laravel Projects at Once: Port Slots and Local HTTPS with Traefik

How I Run Many Laravel Projects at Once: Port Slots and Local HTTPS with Traefik

Every fresh Laravel Sail project wants the same ports: 80 for the app, 3306 for MySQL, 6379 for Redis, 5173 for Vite, 1025 and 8025 for Mailpit. That's fine when you have one project. Start a second one and Docker stops you cold:

Error response from daemon: driver failed programming external connectivity on endpoint
crm-mysql-1: Bind for 0.0.0.0:3306 failed: port is already allocated

The usual fix is sail down in one folder and sail up -d in the other, all day long. I stopped doing that. My machine keeps a registry of around 30 Docker-based projects, about a third of them Sail apps, plus a few native Node and Python tools. Most of them have their own port slot and can run side by side, and most of the Sail apps also answer on their own HTTPS domain, like https://crm.localhost, with a certificate the browser trusts. The rest still use their slot ports until I next touch them.

If you run an agency or a team, this is the part of onboarding nobody writes down: how a developer gets a client repo running next to the five others they already have open, without breaking any of them. The setup has two parts. A port scheme that guarantees no two projects bind the same host port, and one shared Traefik container that owns ports 80 and 443 and routes by hostname. Here's all of it, with the exact files.

How do you run multiple Laravel Sail projects at the same time?

Give every project its own two-digit port slot and set Sail's port variables in .env to match: APP_PORT=8092, FORWARD_DB_PORT=3392, FORWARD_REDIS_PORT=6392, VITE_PORT=5192 and so on. Then run one shared Traefik container on ports 80 and 443 that routes each project's hostname to its container over HTTPS.

Sail already reads every host port from an environment variable with a default. Open any Sail compose.yaml and you'll see mappings like '${FORWARD_DB_PORT:-3306}:3306'. Nothing needs patching. You only need a rule for picking values so they never collide, and a place to write down who owns what.

The slot scheme: one number per project

Each project gets a slot, a two-digit number like 92. To get a project's ports, take each Sail default and replace its last two digits with the slot. MySQL 3306 becomes 3392. Redis 6379 becomes 6392. The app's port 80 becomes 8092.

VariableSail defaultSlot 92Slot 96
APP_PORT8080928096
VITE_PORT517351925196
FORWARD_DB_PORT330633923396
FORWARD_REDIS_PORT637963926396
FORWARD_MEILISEARCH_PORT770077927796
FORWARD_MAILPIT_PORT102510921096
FORWARD_MAILPIT_DASHBOARD_PORT802581928196

Look at the Mailpit dashboard row. 8025 with the slot applied gives 8092, which is already APP_PORT. The rule for that case: a port that lands on another variable of the same project moves up a hundred, so it becomes 8192. If a project also runs Reverb (default 8080), that one lands on 8092 as well, takes 8192, and pushes the Mailpit dashboard up to 8292. Postgres (5432), MinIO (9000) and anything else Sail adds follow the same rule.

Why this beats "just pick a free port": you can read the owner off any port number. If something is listening on 3394, I know it's slot 94 without looking anything up.

Slots start at 90 and go up to 99, then from 89 down to 60. That's 40 slots, more than one machine needs. Stock defaults count as slot 0, and slot 0 always clashes, because ports 80 and 443 belong to Traefik (more on that below). Watch slot 80 too: its APP_PORT is 8080, which is exactly what older Docker projects like to hardcode.

What the .env looks like

Here are the port lines from this site's own repo, which sits in slot 96:

APP_URL=https://iadil.local
APP_PORT=8096
VITE_PORT=5196
FORWARD_DB_PORT=3396
FORWARD_REDIS_PORT=6396
FORWARD_MEILISEARCH_PORT=7796
FORWARD_MAILPIT_PORT=1096
FORWARD_MAILPIT_DASHBOARD_PORT=8196

DB_PORT=3306
REDIS_PORT=6379
MAIL_PORT=1025

SESSION_COOKIE=iadil_session
TRUSTED_PROXIES=*

Notice DB_PORT=3306 didn't change. It looks like a miss, and it's the line I second-guessed most when I set this up. For the database, Redis and Mailpit, only the host side of the mapping moves. Inside Docker, Laravel reaches MySQL as mysql:3306 over Sail's own network, by service name. FORWARD_DB_PORT is just the door your database client uses from outside. Same for REDIS_PORT and MAIL_PORT.

Vite is the exception. Sail maps it as '${VITE_PORT:-5173}:${VITE_PORT:-5173}', so both sides change, and the dev server inside the container has to bind the new port too. laravel-vite-plugin handles that: inside Sail it reads VITE_PORT from .env unless vite.config.js hardcodes server.port. If yours does, change it to match, or the dev server keeps binding 5173 while Docker forwards 5192 and hot reload quietly goes nowhere.

Two settings that break side-by-side runs quietly

  • SESSION_COOKIE. Laravel 12 names the session cookie after APP_NAME, and every fresh project ships with APP_NAME=Laravel, so they all use laravel-session. Browser cookies ignore the port. On separate Traefik hostnames that's harmless, since cookies are scoped to the host. On the localhost:80NN fallback, two apps share one cookie jar, and logging into one logs you out of the other. Set it to <project>_session and stop thinking about it.
  • APP_URL. Leave it at http://localhost and every generated link, redirect, signed URL and email button points at whichever app happens to own port 80.

There's also a third, rarer one. Compose uses the folder name as the project name. Two repos in folders with the same basename (say, two client projects both checked out as api) get the same project name, so the second sail up treats the first project's containers as its own and recreates them with the second project's code. They also share the api_sail-mysql volume. Set COMPOSE_PROJECT_NAME to something unique only in that case, since renaming an existing project points it at a new, empty volume.

Plain Docker Compose projects (Symfony, legacy PHP)

Not every repo uses Sail. Older Symfony and plain PHP projects, the kind I usually meet before an upgrade to Symfony 8 and PHP 8.5, often ship a docker-compose.yml with hardcoded ports and fixed container names:

services:
    php:
        container_name: php
    nginx:
        container_name: nginx
        ports:
            - "8080:80"
            - "443:443"
    db:
        container_name: mysql
        ports:
            - "3306:3306"

That file can only run once per machine. Two projects written like this fail on the port first, and if you fix that, they fail on the name:

Error response from daemon: Conflict. The container name "/php" is already in use by container "..."

The same slot idea applies, with a slightly different port map because these projects run nginx or Apache instead of Sail's PHP server:

ServiceHost port
HTTP (nginx / Apache)80NN
HTTPS84NN
phpMyAdmin, Adminer, other web UIs81NN
MySQL / MariaDB33NN
Postgres54NN
Redis63NN
Mailpit SMTP10NN
Vite51NN

Then three edits to the compose file. Pin the project name at the top, delete every container_name, and turn each kept mapping into a variable with the slot's port as its default:

name: shop

services:
    php:
        build: ./docker/php
    nginx:
        ports:
            - "${NGINX_HTTPS_PORT:-8493}:443"
    db:
        image: mysql:8.4
        ports:
            - "${DB_PORT:-3393}:3306"

A few details that matter:

  • The name: should equal the folder's basename. That's what Compose used before, so existing volumes like shop_db_data are reused instead of starting empty. Check with docker volume ls before you restart.
  • Without container_name, containers become shop-php-1. In-network addresses like fastcgi_pass php:9000 or DATABASE_URL=mysql://...@db:3306 use the service name and keep working. Scripts and READMEs that say docker exec php need to become docker compose exec php.
  • Defaults live in the compose file, not only in .env, because in Symfony and Laravel repos .env is committed and everyone on the team should get working ports from a fresh clone.
  • Check which ports actually serve something. If nginx only has listen 443, the :80 mapping is dead weight. Drop it instead of renumbering it.

Two commands confirm the result: docker compose config --quiet passes, and docker compose config | grep published lists only ports ending in your slot.

One Traefik container for local HTTPS on every project

Unique ports solve the clashes, but http://localhost:8092 is a poor way to develop. Some things want a real hostname and HTTPS: secure cookies, OAuth callback URLs, service workers, payment and maps SDKs that refuse plain HTTP, and anything that checks the Origin header.

So one Traefik container owns host ports 80 and 443 for the whole machine. Any container with traefik.enable=true on a shared Docker network called traefik gets routed by hostname. HTTP redirects to HTTPS. The project keeps its slot ports as a fallback and for database clients.

Here's the whole proxy, in ~/traefik/compose.yaml:

name: traefik

services:
    traefik:
        image: 'traefik:v3'
        restart: unless-stopped
        command:
            - '--providers.docker=true'
            - '--providers.docker.exposedbydefault=false'
            - '--providers.docker.network=traefik'
            - '--providers.file.directory=/dynamic'
            - '--providers.file.watch=true'
            - '--entrypoints.web.address=:80'
            - '--entrypoints.web.http.redirections.entrypoint.to=websecure'
            - '--entrypoints.web.http.redirections.entrypoint.scheme=https'
            - '--entrypoints.websecure.address=:443'
            - '--entrypoints.websecure.http.tls=true'
            - '--api.dashboard=true'
        ports:
            - '80:80'
            - '443:443'
        volumes:
            - '/var/run/docker.sock:/var/run/docker.sock:ro'
            - './certs:/certs:ro'
            - './dynamic:/dynamic:ro'
        networks:
            - traefik
        labels:
            - 'traefik.enable=true'
            - 'traefik.http.routers.dashboard.rule=Host(`traefik.localhost`)'
            - 'traefik.http.routers.dashboard.entrypoints=websecure'
            - 'traefik.http.routers.dashboard.service=api@internal'

networks:
    traefik:
        name: traefik

Start it once with docker compose up -d, and restart: unless-stopped brings it back whenever Docker starts. The settings that do the real work:

  • exposedbydefault=false means Traefik ignores every container that doesn't opt in with a label. Your databases and Redis never get routes by accident.
  • providers.docker.network=traefik tells Traefik which network to use when a container sits on several. A Sail app is on both sail and traefik, and without this Traefik may pick an IP it can't reach.
  • The file provider watches dynamic/. That's where certificates get registered, and Traefik picks up new files without a restart.
  • The dashboard at https://traefik.localhost/dashboard/ lists every router and shows errors when a label is wrong. It's the first place I look when a domain returns 404.

Two cautions. I use the floating traefik:v3 tag, which is fine on a dev machine; pin a specific v3 minor if you want an update to never surprise you. And the Docker socket mount gives the container root-equivalent control over Docker, read-only flag or not. That's an acceptable trade on a local machine and a reason to keep this exact file away from servers.

Certificates with mkcert

mkcert creates a local certificate authority, installs it in your system trust store, and signs certificates with it. Run mkcert -install once (on Linux, Firefox and Chrome use the NSS store, which needs certutil from the libnss3-tools package). Then, per project:

cd ~/traefik
mkcert -cert-file certs/crm.pem -key-file certs/crm-key.pem \
    crm.test crm.localhost '*.crm.localhost'

cat > dynamic/crm.yml <<'YAML'
tls:
    certificates:
        - certFile: /certs/crm.pem
          keyFile: /certs/crm-key.pem
YAML

Traefik matches the certificate to the hostname the browser asks for, so one file per project is all it takes. The wildcard *.crm.localhost covers mailpit.crm.localhost and any other subdomain you add later.

The dashboard needs the same treatment. Without a certificate for traefik.localhost, Traefik serves its built-in self-signed default and the browser complains. I give it its own pair, exactly like a project:

mkcert -cert-file certs/traefik.pem -key-file certs/traefik-key.pem traefik.localhost

cat > dynamic/traefik.yml <<'YAML'
tls:
    certificates:
        - certFile: /certs/traefik.pem
          keyFile: /certs/traefik-key.pem
YAML

If you'd rather have a catch-all, Traefik also accepts a fallback under tls.stores.default.defaultCertificate in a dynamic file, used whenever no other certificate matches.

If you work in WSL like I do, there's a catch: the browser runs on Windows and trusts the Windows certificate store, not the Linux one. So I run the Windows build, mkcert.exe, from WSL, generate the files in a Windows directory, and move them into ~/traefik/certs/. The CA lives on the Windows side, and every browser there trusts the certificates.

Picking hostnames: .localhost, .test, and the .local trap

*.localhost names resolve to 127.0.0.1 in Chromium-based browsers and Firefox with no hosts-file entry, so crm.localhost works the moment the route exists. For a shorter name, add a hosts-file line (C:\Windows\System32\drivers\etc\hosts on Windows, /etc/hosts elsewhere) and include it in the certificate. Use .test, which is reserved for exactly this.

Avoid .local unless you know your OS. It's reserved for multicast DNS (RFC 6762). On macOS, a hosts-file .local name can stall for seconds while Bonjour tries first, and on Linux with nss-mdns it can fail to resolve at all. My machine is Windows with WSL, where hosts-file .local names work fine, which is why this site runs at iadil.local. I wouldn't hand that to a team with Macs.

Labels on the Sail project, in an override file

Before the labels, one rule: don't commit Traefik config into a repo other people clone. If compose.yaml declares the traefik network as external, every teammate without that network gets network traefik declared as external, but could not be found on their next sail up. Put the network and labels in an override file and keep it out of git.

Sail's file is compose.yaml, and Compose automatically loads compose.override.yaml next to it (docker-compose.override.yml pairs with docker-compose.yml the same way). Add it to .gitignore, or to .git/info/exclude when you don't want to touch the team's .gitignore. On my own personal repos, where I'm the only one cloning, I put the labels straight into compose.yaml.

# compose.override.yaml (not committed)
services:
    laravel.test:
        networks:
            - sail
            - traefik
        labels:
            - 'traefik.enable=true'
            - 'traefik.http.routers.crm.rule=Host(`crm.test`) || Host(`crm.localhost`)'
            - 'traefik.http.routers.crm.entrypoints=websecure'
            - 'traefik.http.services.crm.loadbalancer.server.port=80'
    mailpit:
        networks:
            - sail
            - traefik
        labels:
            - 'traefik.enable=true'
            - 'traefik.http.routers.crm-mailpit.rule=Host(`mailpit.crm.localhost`)'
            - 'traefik.http.routers.crm-mailpit.entrypoints=websecure'
            - 'traefik.http.services.crm-mailpit.loadbalancer.server.port=8025'

networks:
    traefik:
        external: true

The router and service name is the project name, which keeps them unique across projects. loadbalancer.server.port=80 is the container port, not APP_PORT: Traefik talks to the container directly over the shared network, so the host mapping doesn't matter to it. external: true tells Compose the network already exists (the Traefik stack created it). Run docker compose config -q to catch YAML mistakes before you restart.

Mailpit gets its own subdomain, so every project's mail catcher lives at https://mailpit.<project>.localhost and I never have to remember which 81NN port it's on.

Tell Laravel it's behind a proxy

Traefik terminates HTTPS and forwards plain HTTP to the container. Laravel sees an HTTP request, so url(), route(), form actions and Livewire endpoints come out as http://, and the browser blocks them as mixed content. Laravel needs to trust the X-Forwarded-Proto header Traefik sends.

Laravel's TrustProxies middleware falls back to config('trustedproxy.proxies') when no proxies are set in code. So add a small config file:

<?php

// config/trustedproxy.php
return [
    'proxies' => env('TRUSTED_PROXIES'),
];

Set TRUSTED_PROXIES=* in your local .env, and put a commented copy in .env.example. Leave it unset in production. When the value is null, the middleware keeps its built-in behaviour: it trusts proxies automatically on Laravel Cloud and on default *.on-forge.com and *.on-vapor.com hostnames, and nowhere else. So this file doesn't change what production does. For Symfony, the equivalent is TRUSTED_PROXIES in .env.local plus framework.trusted_proxies and trusted_headers in config/packages/framework.yaml.

Vite hot reload on an HTTPS page

Traefik serves the page, but Vite's dev server doesn't go through it. The page loads from https://crm.localhost while scripts and the HMR socket come from http://localhost:5192. Two things make that work.

First, Chromium-based browsers and Firefox treat loopback addresses like localhost as potentially trustworthy, so loading http://localhost assets into an HTTPS page isn't blocked as mixed content. Second, the dev server has to allow the page's origin through CORS. Vite's default already allows localhost and *.localhost origins, and laravel-vite-plugin adds your APP_URL and any *.test origin. On this site I went simpler and opened CORS up entirely, which is fine for a dev server bound to my own machine:

server: {
    host: '0.0.0.0',
    hmr: {
        host: 'localhost',
    },
    cors: true,
    watch: {
        ignored: ['**/storage/framework/views/**'],
    },
},

hmr.host: 'localhost' makes the browser connect to the forwarded port on the host instead of the container's internal address. If HMR fails on a hostname you added by hand, check the browser console for a CORS error first.

Verify it with curl

After vendor/bin/sail up -d, two commands tell you whether it works:

CA="$(mkcert -CAROOT)/rootCA.pem"

curl -s -o /dev/null -w '%{http_code}\n' \
    --resolve crm.test:443:127.0.0.1 --cacert "$CA" https://crm.test/

curl -s --resolve crm.test:443:127.0.0.1 --cacert "$CA" https://crm.test/ \
    | grep -oE '(href|src)="http:[^"]*"'

The first should print 200. The second should print nothing. Any output there is an http:// link in your HTML, which almost always means TRUSTED_PROXIES isn't being read or APP_URL still starts with http. On WSL, point CA at the rootCA.pem in the Windows mkcert folder.

Apps that don't run in Docker

The same proxy can front a dev server running straight on the host, like a Node app. Give it a slot like everything else, so a Node server in slot 89 listens on 3089 (30NN). Docker labels can't help here, so the route goes into a file in dynamic/:

tls:
    certificates:
        - certFile: /certs/board.pem
          keyFile: /certs/board-key.pem
http:
    routers:
        board:
            rule: 'Host(`board.test`) || Host(`board.localhost`)'
            entrypoints:
                - websecure
            service: board
    services:
        board:
            loadBalancer:
                servers:
                    - url: 'http://host.docker.internal:3089'

Docker Desktop resolves host.docker.internal to the host machine. On plain Docker Engine on Linux, add extra_hosts: ['host.docker.internal:host-gateway'] to the Traefik service, and make the dev server listen on 0.0.0.0: a server bound only to 127.0.0.1 isn't reachable from inside a container that way.

The registry: write down who owns what

None of this holds up past five or six projects without a list. Mine is one Markdown file, ~/.claude/project-registry.md, with a row per project:

| Name | Path | Framework | Runtime | Slot | Ports | URL | Updated |
|---|---|---|---|---|---|---|---|
| crm | ~/projects/crm | Laravel 12 | sail | 92 | traefik=crm.test, APP_PORT=8092, VITE_PORT=5192, FORWARD_DB_PORT=3392, FORWARD_REDIS_PORT=6392 | https://crm.test | 2026-05-04 |
| shop | ~/projects/shop | Symfony 7 | docker | x93 | NGINX_HTTPS_PORT=8493, DB_PORT=3393 | https://localhost:8493 | 2026-05-04 |
| traefik | ~/traefik | Traefik v3 | docker | - | web=80, websecure=443 | https://traefik.localhost/dashboard/ | 2026-05-04 |

Before assigning a slot, I check that no row holds it and that nothing is actually listening on its ports right now. The second check catches the projects nobody wrote down, and docker ps tells me whether a listener is just this same project already running:

ss -ltnH | awk '{print $4}' | grep -oE '[0-9]+$' | sort -un
docker ps --format '{{.Names}} {{.Ports}}'

On WSL there's one more thing that can block a port nobody is using: Windows reserves dynamic port ranges for Hyper-V and other services. If a slot port refuses to bind with nothing listening on it, netsh interface ipv4 show excludedportrange protocol=tcp on the Windows side shows the reserved ranges.

The registry is also honest about what isn't fixed yet. A handful of older repos in mine still hardcode 8080, 443 and 3306 with fixed container names. Their rows say so and list exactly which projects they clash with, and I convert them when I next work on them.

The less obvious reason it's a Markdown file: Claude Code reads it. My global instructions tell it to check the registry before choosing any port, and the slot rules above live in two Claude Code skills, one for Sail projects and one for plain Compose projects. When I open an unregistered project, the agent detects the framework and runtime from composer.json and the compose file, reads the current ports from .env, proposes a free slot, shows me the exact lines it would change, and waits for a yes. It doesn't restart anything. It tells me to run vendor/bin/sail down && vendor/bin/sail up -d myself, because that stops a stack I might be using. I wrote more about this approach in building software for agents, not just humans: a plain file with clear rules is something both people and AI tools can follow, and the agent applies the rules more consistently than I do at the end of a long day.

Common mistakes

SymptomCauseFix
port is already allocated on 80 or 443Project still on Sail defaults (slot 0), Traefik owns those portsAssign a slot, set APP_PORT=80NN
App can't connect to MySQL after the changeDB_PORT was changed to the forwarded portPut DB_PORT back to 3306
Teammate's sail up fails on network traefikExternal network committed to compose.yamlMove it to an ignored compose.override.yaml
Logging into one app logs you out of anotherSame session cookie name on the same hostSet SESSION_COOKIE=<project>_session
Mixed-content warnings, forms post to http://Laravel doesn't trust Traefik's headersTRUSTED_PROXIES=* locally, APP_URL=https://...
Domain returns 404 from TraefikContainer not on the traefik network, or label typoCheck the router list on the Traefik dashboard
Vite HMR never connectsserver.port hardcoded, or CORS blocks the page originMatch VITE_PORT, check the console for CORS
Database is suddenly emptyProject name changed, so Compose created a new volumeSet name: to the old folder basename

FAQ

Do I need to change DB_PORT when I change FORWARD_DB_PORT?

No. DB_PORT is the port Laravel uses inside Docker to reach the mysql service, and that's always 3306. FORWARD_DB_PORT is only the host port your database GUI connects to. The same split applies to REDIS_PORT / FORWARD_REDIS_PORT and MAIL_PORT / FORWARD_MAILPIT_PORT.

Why Traefik and not nginx-proxy or Caddy?

All three can work. nginx-proxy and caddy-docker-proxy also discover containers on their own, and Caddy can issue local certificates without mkcert. I picked Traefik because routing lives in per-project labels, the file provider routes non-Docker apps through the same entry point, and the dashboard shows every router and its errors in one place. If you already know one of the others well, use that.

Why not Laravel Herd or Valet?

For a machine full of modern Laravel apps on similar versions, Herd or Valet is a perfectly good choice and serves PHP natively. My mix is different: each Sail project pins its own PHP, MySQL and Redis versions to match its production and CI, and the older Symfony repos ship their own Docker stacks that a native setup wouldn't run as-is. Containers per project plus one proxy covers both.

Does this work with Symfony or plain Docker Compose projects?

Yes. The port scheme is the same idea with an nginx-style port map, and Traefik doesn't care what framework is behind a container. Symfony needs its own trusted-proxy settings in framework.yaml, and fixed container_name entries have to go before two projects can run at once.

Do I still need the slot ports once Traefik is in place?

Keep them. Database clients, Redis tools, Mailpit's SMTP port and Vite connect directly, not through Traefik. http://localhost:80NN is also a handy fallback when you're debugging the proxy itself.

Need a senior engineer who can run your stack on day one?

I've spent 15 years building PHP, Laravel, Symfony and React software for US brands, and I keep a lot of client projects running locally at once. Setups like this are why switching between them takes one cd instead of a round of sail down. Lately I'm also building AI automation and MCP tooling for Laravel and Symfony apps.

If your company needs a developer who can take over an existing Laravel or Symfony app, untangle its Docker setup and ship features, or you run an agency and want a white-label senior engineer on client work, have a look at what I offer.

Send me a short note about the project and I'll reply within one business day.