Getting started
Laravel for Rust
Deploy a Laravel for Rust application with Brewless, from the crate and brewless.yml to the build, the edge, the queue, files and what is not there yet.
On this page
- What is supported
- What you need
- Setting it up
- 1. Add the crate
- 2. Register the provider
- 3. Start the application through the crate
- 4. Connect the project
- 5. Deploy
- What the build does
- The build cache
- Release commands
- Variables your application gets
- The edge
- Queue and schedule
- Jobs on Scaleway Queues
- The schedule
- When the worker sleeps
- Files
- Deploy on push
- What is different from Laravel for PHP
- What is not there yet
- When something goes wrong
Laravel for Rust compiles an application to one binary that speaks HTTP itself. Brewless builds that binary, runs its migrations and puts it live as a serverless container in your own Scaleway project, behind bunny.net, with the same commands as Laravel for PHP. This page says what is different. Everything it does not name works as the rest of this documentation describes.
Warning
Laravel for Rust is a beta at version 0.x, and its APIs may change before 1.0. The
brewless-laravelcrate is released to follow it, so keep both up to date together.
What is supported
| For a Laravel for Rust application | |
|---|---|
| Build, release and rollback | Yes |
Release commands and brewless command |
Yes, as subcommands of your own binary |
| Database | Scaleway Serverless SQL or a Managed Database, as DATABASE_URL |
| Edge cache, private origin and Shield | Yes |
| Queue and schedule | Yes, with crate 0.3. Jobs on Scaleway Queues are delivered as they arrive. See Queue and schedule |
| Bucket for files | Yes, with the framework's s3 Cargo feature. See Files |
| Scaleway Transactional Email. See Mail. Not Lettermint | |
| Deploy on push | Yes. The workflow for GitHub Actions tests with cargo test --locked |
| The deploy button | Yes, for a public repository whose Cargo.toml depends on laravel-rust |
What is not there is listed under What is not there yet. Every plan includes Laravel for Rust at the same price as Laravel for PHP. What was measured on a trial application is on brewless.eu/rust.
What you need
- A Laravel for Rust project: a
Cargo.tomlwith thelaravel-rustdependency, at version 0.1.x, and a committedCargo.lock. - The Brewless command line client at version 1.8.0 or later.
- PHP 8.4 or newer on the machine that deploys. The client is a PHP program, also when the project is not. Your application and its container need no PHP.
- A Scaleway account and an organisation at Brewless, as in the Quickstart. Its steps 0, 1 and 2 are the same.
Setting it up
1. Add the crate
cargo add brewless-laravel
brewless-laravel is the Cargo counterpart of the Composer package brewless/laravel. It answers on the same paths, so Brewless can run the release commands, the schedule and the queue, and it reads the same variables. It is on crates.io under the MIT licence, and works with laravel-rust 0.1.x. This page describes version 0.4.
What your environment has decides the Cargo features you switch on, on the framework and on the crate:
| The environment has | Feature of laravel-rust |
Feature of brewless-laravel |
|---|---|---|
A queue at Scaleway Queues (queue: sqs) |
sqs |
sqs, for signed jobs |
| A bucket for files | s3 |
s3, only for the helper that makes a file public |
| Mail through Scaleway | none | mail, which is on by default |
In Cargo.toml that is written on the two dependencies. With a PostgreSQL database, a queue and a bucket:
laravel-rust = { version = "0.1", features = ["database-postgres", "sqs", "s3"] }
brewless-laravel = { version = "0.4", features = ["sqs", "s3"] }
2. Register the provider
Rust has no package discovery, so this line is written by hand:
.with_providers(|providers| {
providers.add(brewless_laravel::BrewlessServiceProvider);
})
3. Start the application through the crate
In src/main.rs, replace app::configure().run() with:
brewless_laravel::run(app::configure())
This is the framework's own run, with its console commands and its graceful shutdown, and one thing more. Behind the edge the container sees its own address as the host and 127.0.0.1 as the peer. Laravel for Rust 0.1.2 and 0.1.3 decide where a request came from before any middleware runs, and give a package no place to change that. So when a request carries the edge secret, brewless_laravel::run takes over the host bunny.net names in Cdn-Host and the visitor's address, and routes the request once with them. Without the valid secret, forwarded headers are not believed.
With the line, generated URLs and redirects use your own domain, and request.ip() is the visitor. We measured this on a trial application on Scaleway, behind bunny.net. Without the line your pages still work, but generated URLs and redirects point at the container's address.
4. Connect the project
brewless init
init recognises the project from the laravel-rust dependency in Cargo.toml, creates the application and writes brewless.yml. It then asks for the environments, as described under init.
organisation: acme
application: shop
framework: laravel-rust
release:
- 'migrate --force'
environments:
production:
edge:
cache: 1h
There is no php line. A file with framework: laravel-rust and a php line is refused. Commit brewless.yml, Cargo.toml and Cargo.lock: a deploy builds what is committed.
5. Deploy
brewless deploy production
The client prints each step as it finishes. Deployments explains the steps around the build.
What the build does
The build runs as a Serverless Job in your own Scaleway project, with 4 vCPU and 8 GB of memory, and may take up to an hour. It runs on ghcr.io/brewless/brewless-builder:rust1.100, with Rust 1.100 and Node 24. There is one toolchain version for now.
- With a
package-lock.jsonin the project:npm ciandnpm run build. The frontend comes first, so what Vite writes is there when Cargo compiles. cargo build --release --locked.- The
buildcommands of yourbrewless.yml, if any.
The binary goes into the image as .brewless/app, next to public/, resources/views/ and storage/. Your source is not in the image. The image is built on ghcr.io/brewless/brewless-base:rust-bare: the C library, certificates and time zones of Debian trixie, and nothing else. It has no shell and no package manager, and runs as www-data. The binary needs libc, libm and libgcc from it. A release built before 2 December 2026 stands on brewless-base:rust, a whole Debian, until its next deploy or the next security update of the base image. The server listens on 0.0.0.0:8080, which the image sets with SERVER_HOST and SERVER_PORT.
The build cache
Compiling every crate takes minutes, so Cargo's downloads and compiled dependencies are kept between builds. They are kept as one object, compressed with zstd, in the bucket of your project that the source is uploaded to.
- The job gets a link to fetch that object and a link to put it back. It never holds a key to your storage.
- It is put back only when
Cargo.lockor the compiler changed. Your own code is compiled again on every commit anyway. - A cache that is missing or cannot be read never fails a build. The build then starts from nothing, as the first one did.
- Before anything is unpacked, the build reads what the object holds. One larger than 4 GiB, or with anything outside
cargo/andtarget/or a link that leads out of them, is not unpacked: the build starts from nothing and keeps a new cache in its place.
A first build grows with what your application compiles. The crate's sqs and s3 features compile the AWS SDK crates, and a first build of a trial application with them took about 19 minutes; without them it took under 8. The cache keeps the builds after it short: the next build with those features took under 3 minutes.
Release commands
Release commands run in the release container before a release goes live, as subcommands of your own binary:
release:
- 'migrate --force'
Migrations are compiled into the binary. The framework has no command to roll a migration back: migrations only go forward, and a change you want to undo is a new migration. brewless rollback puts the previous release back, which is its image. It does not touch the database.
brewless command runs your application's own console commands the same way:
brewless command staging "route:list"
There is no tinker for Rust, so brewless tinker has nothing to run; from CLI 1.8.1 it says so before it asks anything of your application.
Variables your application gets
A new environment is given these, in the names Laravel for Rust reads. A value you set yourself always wins. See Variables.
| Variable | Value |
|---|---|
APP_NAME, APP_KEY, APP_URL |
As for Laravel for PHP |
APP_ENV, APP_DEBUG |
production and false |
LOG_CHANNEL |
stderr, so the logs reach Logs |
DATABASE_URL, DB_CONNECTION |
With a database: its address as one URL, and postgres or mysql |
CACHE_STORE, SESSION_DRIVER |
database with a database, otherwise memory and cookie |
QUEUE_CONNECTION |
Where the jobs wait |
SQS_* |
With a queue at Scaleway Queues: its endpoint and a key of its own, which the crate gives to the sqs connection alone |
AWS_* |
With a bucket: its key, and AWS_URL with the files address. Your application needs the framework's s3 Cargo feature for it |
MAIL_* |
With mail through Scaleway, the same names as Laravel for PHP |
BREWLESS_EDGE_SECRET, BREWLESS_DOMAINS |
What the crate checks a request from the edge with |
BREWLESS_EDGE_CACHE |
The seconds of edge.cache in brewless.yml |
The database address ends in ?sslmode=require for PostgreSQL, so the connection goes over TLS without a change in src/config/database.rs.
The edge
The crate adds Cache-Control: public, max-age=0, s-maxage=<edge.cache> to an answer to a GET or HEAD with status 200 that sets no cookie. bunny.net keeps such a page and answers the next visitor itself, without asking your container. Every release empties the edge. Edge cache describes the edge itself; its sections about sessions and guests are about brewless/laravel for PHP.
A request that says who is asking is never kept: one with a cookie, with Authorization, or, from crate 0.3.1 on, with a header such as X-Api-Key or X-Auth-Token (any name that holds auth, token, api-key, secret, session, signature, tenant or xsrf), X-Requested-With or X-Inertia. Its answer gets Cache-Control: no-cache, private unless your application set a Cache-Control itself. A 404 is kept for a minute at most.
Warning
Use crate 0.3.1 or later when your application tells callers apart by a header of its own. Earlier versions looked at cookies and
Authorizationonly, so an answer to a GET withX-Api-Keywas kept for every visitor. An answer that depends on something the request does not show, such as the visitor's address orAccept-Language, still has to say so itself, withCache-ControlorVary.
A page of a new Laravel for Rust application is not kept. Its routes are in the web group, which starts a session and sets the XSRF-TOKEN and session cookies, and with Inertia adds Vary: X-Inertia. A page that sets a cookie is never kept by the edge.
To let the edge keep a public page, take those middleware off its route:
.without_middleware::<StartSession>()
.without_middleware::<PreventRequestForgery>()
With Inertia, also:
.without_middleware::<HandleInertiaRequests>()
Check it by asking for the page twice. The second answer should carry cdn-cache: HIT:
curl -sI https://shop.example.eu/ | grep -i cdn-cache
Queue and schedule
Nothing stays running on a serverless container, so something has to call the worker. With crate 0.3 that is the queue and the schedule themselves, and nothing else. Both were used on Scaleway with a trial application.
Jobs on Scaleway Queues
With queue: sqs, switch on the sqs feature of the framework and of the crate, as under Add the crate. Your application changes nothing else: the connection is still called sqs.
- The crate signs every job your application puts on the
sqsconnection, with a key derived fromAPP_KEYand the environment (BREWLESS_ENVIRONMENT, which Brewless gives every container). - Scaleway Queues delivers each message to the worker container as it arrives.
- The crate checks the signature and runs that one job, with a worker of its own, so the job's tries and the failed jobs apply as they do for
queue:work.
A message that is unsigned, was changed on the way, was signed in another environment or was signed more than an hour ago is dropped. So is a second delivery of a job that was handled already. Two environments that share an APP_KEY and name their queue alike therefore still never run each other's jobs (from crate 0.4). A job that fails for good is kept with the failed jobs once, and Try failed jobs again in the console puts it back. Failed jobs need a database.
The queue gets a key of its own, separate from the bucket's, and the two work side by side.
What is not signed, and so not delivered this way: a FIFO queue, and a job the framework kept in its cache because it was too large for a message. Signed jobs are for sqs only. With jobs in the database (queue: database) the worker is called every minute and runs queue:work --stop-when-empty --max-time=45, as described under How the worker is called.
The schedule
A Scaleway cron calls the worker container at the moments your schedule has work, and the crate runs schedule:run. The framework reads every schedule in UTC: it has no time zone for a task. The Schedule tab of the console lists your tasks and those moments. A task you add or change gets its moment with the next deploy.
When the worker sleeps
With the queue at Scaleway Queues, the worker is called for a job and for a task that is due, and for nothing in between. With an hourly task the Schedule tab says "Every hour at :00", and the worker can scale to zero between two calls.
Scaleway writes no log line when it scales a container to zero. You see that it slept by the next Server running line in Logs, written when it starts again.
Warning
Upgrading from crate 0.3 to 0.4 changes the signing key. A job that 0.3 signed and that is still on the queue when the new release goes live is dropped once, with a warning in the log that its signature does not hold. Deploy when the queue is empty, or dispatch such jobs again.
Warning
Crate 0.2 does not sign jobs, and neither does 0.3 without its
sqsfeature. Brewless then calls the worker every minute to look for jobs, and neither the worker nor a serverless database gets to sleep. Upgrade to 0.3, switch the feature on and deploy.
Files
With a bucket, switch on the framework's s3 feature. The framework's s3 disk then reads and writes the bucket, and a temporary URL leads to the bucket itself, also for a private file.
With bunny.net in front, the bucket gets a files address, and a deploy gives it to the containers as AWS_URL once the address answers with its certificate. The first deploy after the address was added still gives the bucket's own address; the next one gives the files address.
The edge asks the bucket without a key, so it serves only a public file. The framework writes every file private and has no option for it. Until it has, the crate makes a file public after the write, with its s3 feature:
let disk = laravel::storage::default_disk()?;
disk.put("avatars/1.png", bytes).await?;
brewless_laravel::files::make_public("avatars/1.png").await?;
let url = disk.url("avatars/1.png").await?;
make_private(path) takes it back, and make_public_on(disk, path) names another disk. The edge keeps a public file for a day, so give a file that changes a new name.
With mail: scaleway, the crate adds an smtp mailer for Scaleway Transactional Email. It reads the same MAIL_* variables as Laravel for PHP, and is in the crate's mail Cargo feature, which is on by default. See Mail for the domain and its DNS records.
mail: lettermint does not work for this framework: Lettermint has no package for Rust.
Note
On a trial application, a mail sent through this mailer, signed in over STARTTLS on port 587, was accepted by Scaleway Transactional Email, showed on the Mail page of the console, and arrived in the inbox it was sent to.
Deploy on push
Deploy on push works as for any application. The workflow the console writes for GitHub Actions tests a Rust application with cargo test --locked, next to PostgreSQL 18, and deploys with the command line client. Its deploy job sets PHP up for the client. See A whole workflow for GitHub Actions.
What is different from Laravel for PHP
| Laravel for PHP | Laravel for Rust | |
|---|---|---|
| Package | composer require brewless/laravel, discovered by itself |
cargo add brewless-laravel, a provider line and a line in src/main.rs |
In brewless.yml |
framework: laravel and a php version |
framework: laravel-rust, no php line |
| A build | Installs your Composer packages | Compiles your application, which takes minutes |
| The image | FrankenPHP with PHP and your code | Your binary on the C library and certificates, without a shell and without your source |
| Database | DB_HOST and the other parts |
One DATABASE_URL |
| A public page | Kept by the edge while it sets no cookie | Kept once its route is out of the session middleware |
| A line of code in an environment | brewless tinker |
Not there. brewless command runs your own commands |
| Undoing a migration | migrate:rollback |
A new migration |
| Security fixes of the base image | Put under the live release by Brewless | Put under the live release by Brewless, without compiling |
| Security fixes of what you depend on | Composer and npm packages: your next deploy | Crates and Rust's standard library are in the binary: your next deploy |
What is not there yet
- Tinker. There is none for Rust.
- Automatic security updates of what is in the binary. Brewless puts a patched base image under your live release by itself, see Security updates. That changes the Debian packages under the binary and nothing in it: a vulnerability in a crate your application compiled in, or in Rust's standard library, needs a new build, so a deploy. A new Rust release is not taken by itself either.
- API Guardian's own OpenAPI document. Nothing writes one from this framework's routes.
- Realtime on your application's image (
image: app).realtime: trueruns it on Brewless's image, without the closed beta, with the sameREVERB_*variables. That works for Laravel for Go, see Realtime; for Rust it is not tested. - Signed jobs on a FIFO queue or on the database queue, and for a job too large for a message. See Jobs on Scaleway Queues.
- A file written public in one step. The framework writes every file private. See Files.
- What
brewless/laraveldoes inside a PHP application and the crate does not do yet: databases per tenant, the client for Malware Protection, the client for database capacity and edge publishing. - More than one binary or toolchain. A project builds one binary, on Rust 1.100.
When something goes wrong
- "The build must make exactly one binary". Cargo built no binary, or more than one, such as a workspace with two packages that each have one, or a package with two
[[bin]]targets. A project with several binaries is not supported yet. Only what this build made counts: a binary that an earlier build left behind, under a name the package no longer has, is ignored. - The application does not start. A variable names a mailer, a cache store, a disk or a queue connection that your Cargo features do not include, such as
FILESYSTEM_DISK=s3without thes3feature. Add the feature, or change the variable, and deploy. - Redirects and generated URLs point at the container's address.
src/main.rsstill starts the application withapp::configure().run(). See step 3. - A page is never answered by the edge. It sets a cookie. See The edge.
- bunny.net answers 403 for a file. The file is private. Make it public after the write, see Files.
- A link to a file names the bucket, not the files address. The certificate of the files address was not there yet at the last deploy. Deploy once more.
- The worker is called every minute. The crate is older than 0.3, or its
sqsfeature is off. See When the worker sleeps. - The test address. The crate knows the test address of an environment,
<organisation>-<application>-<environment>.brewless.dev, through the variableBREWLESS_PREVIEW_DOMAINS. - The first request after a quiet time is slow. A container that was scaled to zero has to start, and a Serverless SQL Database that slept makes the first query wait. We measured one cold start on a trial application; the figure, and what it includes, is on brewless.eu/rust.
- A
phpline is refused. Take it out ofbrewless.yml: this framework has no PHP version.