---
title: "Deploy Laravel and PostgreSQL over MCP with while.sh"
url: https://while.sh/en/guides/deploy-laravel/
author: "Aloïs Oddon, co-founder of Nextmap"
updated: 2026-11-02
---

# Deploy a Laravel app and its PostgreSQL database from your AI agent, over MCP

Your AI agent already knows how to write Laravel. Connected to while over MCP, it also deploys your app, in France, with its PostgreSQL database backed up every day and a Laravel Dockerfile ready to go.

## Prerequisites

- A Laravel app, with its composer.json and its artisan file.
- An AI agent that works in a terminal: Claude Code, Codex, Cursor or Gemini CLI.

## Step 1: Give your agent these instructions

Open your agent in your app's folder and paste these instructions into it:

```text titre="Instructions"
Connect to while with my account (while.sh/agents), then deploy my app.
```

Without an account, your agent deploys your app as a trial, in one request. To keep it, open the link it gives you and create your account.

With your account, your agent adds while's MCP server itself. If it asks you to, restart it. On the first call to while, a page opens in your browser. In Claude Code, if it doesn't open, type /mcp, choose while, then Authenticate. On that page, choose your app, or "A new app", then click Authorize.

## Step 2: Open your app

Your agent gives you your app's address, for example `https://mon-appli.while.cloud`, over HTTPS.

## What your agent does

It writes while.yaml at the root of your app:

```yaml titre="while.yaml"
apiVersion: while/v1
project: mon-appli
services:
  - name: web
    port: 8080
    health:
      path: /up
databases:
  - name: main
```

while recognizes Laravel by its composer.json and its artisan file, and your agent gets a Dockerfile ready to build: the Composer dependencies, Apache serving the `public` folder, and a user without admin rights. Your agent adds it to your app. If your pages load their assets with Vite, the Dockerfile builds them too, and your pages load them over HTTPS.

At startup, the migrations run, then Apache serves your pages. Laravel reads the database address from `DB_URL` (source 1), which the Dockerfile fills in from `DATABASE_URL`. The `/up` route in Laravel 11 and later tells while that your app is ready (source 2). On an older version, your agent adds it. Your agent also generates the `APP_KEY` key and stores it in while's secret vault.

## Run your queues

> You, to your agent: Add a worker for the email queue.

Your agent declares a worker, with the same image and the `php artisan queue:work` command. Your jobs wait in the PostgreSQL database, which is backed up every day.

## Store uploaded files

> You, to your agent: Store the files our customers upload.

Your agent adds S3-compatible storage to while.yaml and connects Laravel's `s3` disk to it. Your files survive every deployment.

## Run an artisan command every night

> You, to your agent: Run the export command every night at 3 am.

Your agent declares a scheduled job that runs your artisan command at the set time, with the same code and the same database. If it fails, your agent is notified.

## Restrict your app to your colleagues

> You, to your agent: Restrict the app to people in the company.

Your agent adds two lines to the service:

```yaml titre="while.yaml"
    access: internal
    email_domains: [acme.com]
```

Once your Google Workspace or Microsoft 365 is connected to while, on the Pro plan, your colleagues open it with their usual account, and your code receives their name and email address, with no sign-in page to write.

## Move to your own domain

> You, to your agent: Put the app on app.acme.com.

Your agent declares the domain, you add the DNS records it gives you, and the HTTPS certificate follows.

## See a new version before you deploy it

> You, to your agent: Show me the new version before you deploy it.

Your agent opens a preview, at its own address, with its own data. You look at it, then your agent puts it into production.

## Go back to the previous version

> You, to your agent: Go back to the previous version.

In the 30 minutes after a deployment, the previous version comes back in a second. After that, it takes a few seconds. Once the previous version is back, your agent reads what broke in while's logs, fixes it and deploys again.

## Next steps

- [Store your app's files](/en/guides/store-files-s3/)
- [Choose a French PaaS](/en/comparisons/french-paas/)
- [Deploy a Docker container](/en/guides/deploy-docker-container/)

## Sources

1. [Laravel, database configuration (DB_URL)](https://laravel.com/docs/12.x/database#configuration), 2026-11-02
2. [Laravel, the /up health route](https://laravel.com/docs/12.x/deployment#the-health-route), 2026-11-02

## Questions

### Do I need to write a Dockerfile?

No. while recognizes Laravel, and your agent gets a Dockerfile ready to build, with Apache and PHP. If your project already has its own, that one builds the image.

### Are my migrations applied?

Yes, at every startup, with php artisan migrate --force.

### What about queues?

Your agent adds a worker, with the same image and the php artisan queue:work command.

### MySQL or PostgreSQL?

while's database is PostgreSQL, and Laravel connects to it without any change to your code.

### Where is my app hosted?

In France, by Nextmap, a French company.
