Rust Playbook

Course › Week 6 · Laravel Rust › Day 1 · lesson 36 of 42 · 10 min reading + 45 min practice

Laravel Rust: install and the shape of an app

The CLI, a new application, and every folder next to the PHP Laravel one it stands for.

Laravel Rustlaravel CLIapp.rsroute:list

On this page
  1. 1. Install the Laravel CLI
  2. 2. A new application
  3. 3. Every folder, next to the PHP one
  4. 4. src/app.rs, the bootstrap file
  5. 5. Migrations
  6. 6. A first API route
  7. 7. What is underneath
  8. artisan and the laravel command
  9. Practice
  10. Remember

On 1 December 2026 Laravel released the first beta of Laravel Rust: the Laravel framework itself, written in Rust. It is not a bridge to your PHP application and not a way to speed it up. A Laravel Rust application is a Rust program from the first line, with routes, handlers, models, queues and tests organised the way a Laravel developer expects.

It is built on axum and tokio, so Week 5 was not a detour: the router, the extractors, the middleware layers and the async handlers are all still there, with Laravel’s conventions on top. This week builds the Week 5 service again on it, and compares what the framework takes over.

It is a beta. The docs say releases before 1.0 may change APIs and configuration, and four releases came out in its first three days. Everything on these pages is pinned to laravel-rust 0.1.4 and the application skeleton of 1 December, and every output was recorded from them.

1. Install the Laravel CLI

Laravel Rust needs Rust 1.99 or later. The setup page installed 1.100; if your Rust is older, rustup update brings it up to date. You also need Node.js (for the frontend that new applications come with) and Git.

code
rustup update
rustc --version          # 1.99 or later

curl -fsSL https://laravel.com/install.sh | sh
laravel --version        # must start with "Laravel CLI"

The installer puts a new laravel command in ~/.laravel/bin. If you have Laravel Herd or the old Composer installer, they have a laravel command too, and whichever comes first on your PATH wins. If laravel --version prints anything other than Laravel CLI …, move the line the installer added to ~/.zshrc below Herd’s. The new CLI also creates PHP applications, so nothing is lost.

2. A new application

code
laravel new nordic --rust
cd nordic
laravel migrate
laravel dev

laravel new downloads the skeleton, writes .env with a fresh APP_KEY, installs the frontend and compiles the application, which takes a few minutes the first time. laravel dev then starts the application, a queue worker and Vite together, and rebuilds and restarts the application whenever a .rs file or .env changes, like composer dev in a new PHP application.

This course’s application is called nordic and listens on port 3000: the fake Laravel API from Week 4 already uses 8000, the default. One line in .env moves it: SERVER_PORT=3000.

3. Every folder, next to the PHP one

Laravel RustWhat it holdsIn PHP Laravel
src/app.rsRoute files, middleware, migrations and auth, registered in one placebootstrap/app.php
src/routes/web.rs, api.rsRoute files; api.rs routes get the /api prefix and no sessionroutes/web.php, routes/api.php
src/http/handlers/Handlers: async functions, one module per resourceapp/Http/Controllers/
src/http/middleware/Middleware: #[middleware] functionsapp/Http/Middleware/
src/models/Models: structs marked #[model]app/Models/
database/migrations/Migrations, one Rust file each, compiled into the binarydatabase/migrations/
src/config/Config files for what .env cannot expressconfig/
src/console/Console commands and the scheduleapp/Console/, routes/console.php
tests/Tests; each file is its own cratetests/Feature/
resources/, public/The Inertia + React frontend, and static filesthe same

Two differences matter from the first day. The library inside is always named app, whatever the project is called, so your imports read use app::models::User. And there is no autoloading: a new module exists only once a mod line names it, as in the modules lesson. src/lib.rs is where those lines live.

4. src/app.rs, the bootstrap file

app.rs is the application’s bootstrap/app.php: one builder chain that registers the migrations, the authentication guard, the route files, the health route and the middleware. main.rs only calls app::configure().run(), which serves the application, or runs a command when given one.

src/app.rs
use laravel::foundation::ApplicationBuilder;
use laravel::{Application, inertia, model};

use crate::http::middleware::{HandleInertiaRequests, example_middleware};
use crate::models::User;
use crate::routes;

pub fn configure() -> ApplicationBuilder {
    Application::configure()
        .with_migrations(laravel::db::migrations!("database/migrations"))
        .with_schema(laravel::db::schema!("database/schema"))
        .with_auth(|auth, _| {
            auth.session::<model::Users<User>>();
        })
        .with_routing(|routing, _| {
            routing
                .web(routes::web::routes)
                .api(routes::api::routes)
                .channels(routes::channels::routes)
                .health("/up");
        })
        .with_middleware(|middleware, _| {
            middleware.web(|web| {
                web.append(inertia::middleware(HandleInertiaRequests))
                    .append(example_middleware);
            });
        })
}

pub fn create() -> Application {
    configure().create()
}
$ laravel route:list
Method         URI                 Handler
GET|HEAD       /                   welcome::show
GET|HEAD       /api/version        Closure
POST           /broadcasting/auth  laravel::channels::Channels
GET|POST|HEAD  /_workflow/resume   laravel::url::accept
ANY            /{fallback}         Closure
ANY            /api/{fallback}     Closure

route:list is the application’s own command. Like php artisan route:list, it lists every route with its handler, including the framework’s own (/broadcasting/auth for private channels, /_workflow/resume for durable workflows) and the two fallbacks that answer 404. /up, the health route, is answered before routing, so it is not in the list.

laravel route:list and every other laravel command compile the application first, if anything changed, then run it with the command’s name. A new application’s commands are listed by laravel list: migrate, queue:work, schedule:run, make:migration, key:generate and the rest, the names you know from artisan.

5. Migrations

A new application has three migrations: users, cache and the queue tables. They are Rust files in database/migrations, compiled into the binary, so a server runs them with no source code present:

$ laravel migrate
Migrating `0001_01_01_000000_create_users_table`...
Migrating `0001_01_01_000001_create_cache_table`...
Migrating `0001_01_01_000002_create_jobs_table`...
3 migrations ran.
$ laravel migrate:status
Migration                             Batch  Status
0001_01_01_000000_create_users_table  1      ran
0001_01_01_000001_create_cache_table  1      ran
0001_01_01_000002_create_jobs_table   1      ran

Laravel records each migration in a migrations table, as in PHP. The names follow PHP Laravel’s too, down to the 0001_01_01_ dates of the framework’s own migrations. Do not point a Laravel Rust application at the database of a PHP Laravel application: both keep their own migrations table, and each would try to manage the other’s tables.

6. A first API route

A route file is a function that receives the Router. route.get(uri, handler) adds a route; the handler here is a closure, async || …, that returns a response. Json(…) is axum’s, re-exported by Laravel’s prelude, so a #[derive(Serialize)] struct from the serde lesson becomes the body.

src/routes/api.rschanged since the new application: +14
use laravel::prelude::*;use serde::Serialize;use serde_json::json; /// What /api/status reports, for Laravel's health checks and for people.#[derive(Serialize)]struct Status {    service: &'static str,    laravel: &'static str,} pub fn routes(route: &mut Router) {    route.get("/version", async || Json(json!({ "laravel": laravel::VERSION })));    route.get("/status", async || {        Json(Status {            service: "nordic",            laravel: laravel::VERSION,        })    });     route.fallback(async || laravel::abort(404));}
$ curl -si http://127.0.0.1:3000/api/status
HTTP/1.1 200 OK
content-type: application/json
content-length: 38
vary: access-control-request-method, access-control-request-headers
access-control-allow-origin: *
x-frame-options: SAMEORIGIN
x-content-type-options: nosniff
x-request-id: b11720617c647074a5deac0749313130

{"service":"nordic","laravel":"0.1.4"}
$ curl -si http://127.0.0.1:3000/api/nothing-here
HTTP/1.1 404 Not Found
content-type: application/json
content-length: 23
vary: access-control-request-method, access-control-request-headers
access-control-allow-origin: *
x-frame-options: SAMEORIGIN
x-content-type-options: nosniff
x-request-id: 584e9135c715eda74199698defc272c8

{"message":"Not Found"}
$ curl -si http://127.0.0.1:3000/up
HTTP/1.1 200 OK
content-type: text/html; charset=utf-8
x-request-id: a44968f979a475ec26b69b6f8085c39d
content-length: 212

<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><title>Application up</title>
<style>html{min-height:100%;background:linear-gradient(oklch(84.5% 0.143 164.978),#fff)}</style></head><body></body></html>
the server’s log (stderr), after Ctrl-C
Server running at `http://127.0.0.1:3000`. Press Ctrl+C to stop.
GET     200  /api/status  1.2ms
GET     404  /api/nothing-here  2.0ms
Stopping. Waiting up to 20s for the work in progress.

The route is defined as /status and answers at /api/status: the api group adds the prefix. The unknown URI reaches the fallback, whose abort(404) became {"message":"Not Found"}, the shape Laravel gives API clients; a browser asking for a page gets an HTML error page instead. The other headers come from the default middleware: x-frame-options and x-content-type-options for security, and an x-request-id to find the request in the log.

access-control-allow-origin: * deserves a look. The skeleton’s src/config/cors.rs lets any website call the api/* routes from a visitor’s browser, a convenient default for a public API. For an internal service, which only Laravel calls server to server, narrow it as the middleware lesson did: origins: Allowed::only([…]), or no paths at all.

The log has one line per request, with the status and the time it took: the framework’s request logging, the job TraceLayer did in Week 5. /up is missing from it, because the health route answers before any middleware runs, logging included. A load balancer that checks it every few seconds does not fill the log.

7. What is underneath

The Router here wraps an axum router, the handlers are async functions whose arguments are extractors, and the server is tokio’s. Laravel adds the conventions: the route files and their middleware groups, the container that hands handlers their services, models, validation, sessions and the rest.

You can still reach the layer below when you need it. Any tower layer, such as tower-http’s compression, is added in app.rs with middleware.append(layer(…)), and the HTTP client and the database use the same tokio runtime. What Week 5 taught is what this framework runs on, so an error message that mentions axum, tower or sqlx will make sense.

artisan and the laravel command

PHP LaravelLaravel RustThe difference
php artisan migratelaravel migrateThe command compiles the application first, if anything changed
php artisan route:listlaravel route:listThe same table
composer devlaravel devA .rs change means a rebuild: seconds, not instant
php artisan servecargo run --release in productionProduction is one compiled binary; no PHP-FPM, no web server needed
A missing class: a runtime errorA missing mod line or a wrong type: a compile errorMost mistakes are found before the application starts

The rebuild is the honest cost. A one-line change in a handler recompiles the application crate, a few seconds on a recent laptop; PHP shows it on the next request. In exchange, a typo in a route, a model field or a job name stops the build instead of a request in production.

PracticeThe installation and structure guides

Read the installation and directory structure guides. The same guides, for the exact version in your Cargo.lock, are inside the crate: the framework ships its documentation as Markdown files, so ls ~/.cargo/registry/src/*/laravel-rust-0.1.4/docs lists them, readable offline.

Exercise: a route with a parameter

Add route.get("/echo/{word}", …) to api.rs that answers {"word": …}. The closure takes Params(word): Params<String> from the prelude. Try /api/echo/salam, then look at how route:list shows the parameter.

Remember

  • Laravel Rust is Laravel’s own framework written in Rust, on axum and tokio: a new application, not a bridge to a PHP one.
  • src/app.rs is bootstrap/app.php; every laravel command compiles the application, then runs it.

Tomorrow: routes and handlers properly. Handler modules, route parameters, and input validated by its type.