Documentation Frameworks and migration

Deploy Laravel Rust with PostgreSQL on Gregale

A Laravel Rust Docker starter with managed PostgreSQL, release migrations, and a live read/write smoke test.

~3 min read
On this page

Deploy a Laravel Rust HTTP API from a Dockerfile and connect it to Gregale-managed PostgreSQL. Run schema migrations before the new release serves traffic, using a credential the running app never receives.

This guide uses Laravel Rust 0.1.2, a beta Rust framework. It does not run existing PHP Laravel code. For PHP, see Deploy a Laravel app. The example is an HTTP API, not a queue worker or a full Inertia app.

1. Get the starter

Clone the Laravel Rust + PostgreSQL starter or download the ZIP. Run the commands from laravel-rust-postgres. You need the Gregale CLI, an authenticated account with managed PostgreSQL capacity, and python3 for the smoke test.

The Dockerfile compiles the binary using the checked-in Cargo.lock. The web entrypoint listens on 0.0.0.0 and passes Gregale's PORT to Laravel Rust as SERVER_PORT. The container runs as a non-root user.

2. Create an app and attach PostgreSQL

Choose unique names. Keep authentication enabled: the demo's marker routes are meant only for smoke testing.

sh
APP=laravel-rust-demo
DB="${APP}-db"
gregale deploy --name "$APP" --create-only --require-authn
gregale postgres create "$DB" --region us-east-2 --postgres-major 17 --class development --scale-to-zero
gregale postgres get "$DB"

Use a supported database region for your workspace. Wait for the database to show ready, then attach both roles:

sh
gregale postgres attach "$DB" "$APP" --env DATABASE_URL --access read_write
gregale postgres attach "$DB" "$APP" --env MIGRATION_DATABASE_URL --access migration
APP_URL="https://YOUR-APP.gregale.app" # use the URL returned by gregale app get "$APP"
gregale env set --app "$APP" APP_ENV=production APP_DEBUG=false APP_URL="$APP_URL"

Set APP_URL to the actual app URL, including its scheme. In production, Laravel Rust rejects other hosts with HTTP 400 by default. Do not turn this check off just to get the smoke test passing.

The app uses pooled DATABASE_URL to read and write rows. The release task alone gets MIGRATION_DATABASE_URL. The checked-in gregale.yaml runs /app/migrate before the release serves traffic; that script points Laravel at the migration credential and runs migrate --force. If it fails, Gregale does not promote that release. See Managed PostgreSQL for how the roles differ.

3. Deploy and verify a real request

sh
gregale deploy --name "$APP" --require-authn --wait

Run the smoke test against the URL printed by the deploy, with a Gregale API key from the app’s owning account in GREGALE_SMOKE_TOKEN. Do not commit that credential or pass it to the deployed container.

sh
python3 smoke.py "$APP_URL"

The test checks that an anonymous call is refused, reads the framework version from the running app, then inserts a synthetic row and reads its ID back. It also checks that the serving process cannot see the migration credential. /up is the startup check; it does not prove that a query reached PostgreSQL.

Verified on Gregale: The container build and release migration passed with managed PostgreSQL 17. The private app rejected anonymous access, returned HTTP 201 for a synthetic insert, then returned the same row ID on the read. Its serving process did not have MIGRATION_DATABASE_URL.

Do not expose the demo's test routes to the public. When you're done, remove the disposable app and database through the console.

Adapting an existing Laravel Rust project

Keep the port mapping and release command, and change the Docker build and entrypoint to use your binary name. If the app uses Inertia, server-rendered templates or bundled assets, also follow Laravel Rust's deployment guide for frontend builds and the public/, resources/ and storage/ directories. If it uses sessions or signed URLs, set an APP_KEY as a secret. This starter does not verify frontend assets, queues or scheduled tasks.

Spotted a problem on this page? Tell us