Laravel Rust: what it is and how to run your first application
Laravel Rust is the official Laravel web framework for Rust. If you have worked with Laravel in PHP, routes, middleware, and application configuration will be familiar. Here, you write handlers in Rust and compile the application into an executable. The framework is still in beta, so its API may change.
In this lesson, you will add one HTTP route, build the application, and check its responses.
Prepare your environment
For the first application, you will need x86_64 Linux (WSL2 also works), Bash, Rust and Cargo 1.99 or later, a C compiler, a linker, curl, tar, and OpenSSL. If Rust is not installed yet, follow the official Rustup guide.
# Rust version
rustc --version
# Cargo version
cargo --version
Obtain the application skeleton
The official Laravel CLI creates an application with the command below. See the Laravel Rust documentation for CLI installation and full-application requirements. If you use Laravel in PHP, check which installer the laravel command points to.
# Create an application with the Laravel CLI
laravel new example-app --rust
In this lesson we use the official v0.1.2 skeleton archive, so we can go straight to the server without setting up the frontend. I checked the version of CLI 0.3.0, but did not run its project creation command for this example. Create a new directory for the tutorial. Run the commands in Bash as a non-root user. If a command fails, fix the error before continuing.
# Create the project directory
mkdir laravel-rust-demo
cd laravel-rust-demo
# Download the skeleton
curl -fL -o skeleton.tar.gz \
https://codeload.github.com/laravel/rust/tar.gz/refs/tags/v0.1.2
# Extract into the current directory
tar -xzf skeleton.tar.gz --strip-components=1 --no-same-owner --no-same-permissions
Add the route
Cargo.toml describes the package, its dependencies, and build options. It plays a role similar to composer.json, with Cargo also handling compilation. src/main.rs is the entry point, while src/app.rs configures the application and registers its components.
In Laravel PHP, you would usually add a GET route in routes/web.php. In this Laravel Rust skeleton, open src/routes/web.rs and add this one line inside pub fn routes(route: &mut Router), after the / route and before the fallback. Keep the existing laravel::prelude::* import and other routes.
// Register a GET route
route.get("/hello-rust", async || "Hello from Laravel Rust!");
The get method registers a GET handler at the given path. async || defines an asynchronous closure with no arguments. This one returns a string literal, which the framework turns into a plain-text HTTP response.
Configure the local application
Create an .env file in the root of the new project. For this example, sessions and cache use memory, and queue and broadcast work are discarded. A running database is not needed because the route does not access it. First generate an application key:
# Generate the application key
openssl rand -base64 32
Paste the generated string after base64: in APP_KEY, replacing YOUR_GENERATED_KEY. The placeholder itself is not a valid key. The local configuration below is adapted from the tested route scenario. See the skeleton's .env.example file for the setting names. Keep the file accessible only to your user, and do not reuse production keys or commit .env to Git.
# Application
APP_NAME=Laravel
APP_ENV=local
APP_DEBUG=false
APP_URL=http://127.0.0.1:18080
APP_KEY=base64:YOUR_GENERATED_KEY
LOG_CHANNEL=stderr
# Database (not used by this route)
DB_CONNECTION=postgres
DATABASE_URL=postgres://postgres@127.0.0.1:1/laravel
# In-memory sessions and cache
SESSION_DRIVER=memory
CACHE_STORE=memory
# Discard queue and broadcast work
QUEUE_CONNECTION=discard
BROADCAST_CONNECTION=discard
# Local mail and SSR
MAIL_MAILER=log
INERTIA_SSR=false
Fetch dependencies and build the project
The skeleton archive has no Cargo.lock. On the first fetch, Cargo selects dependency versions and records them in the lockfile. Check which framework version was selected: this example used laravel-rust 0.1.4. A fresh copy without that lockfile may resolve different versions. Keep the generated Cargo.lock for repeatable builds of your project.
# Fetch dependencies
cargo fetch --target x86_64-unknown-linux-gnu
# Check the framework version
cargo tree --locked -i laravel-rust
# Build using Cargo.lock
cargo build --offline --locked --target x86_64-unknown-linux-gnu -j 6
Fetching requires internet access, and the build uses the downloaded dependencies. -j 6 limits parallel build jobs. Reduce it if memory is tight. The path below assumes the default target directory. If you configured another build directory, use the actual executable path.
Start the server and check the route
Start the server from the project root:
# Start the local HTTP server
./target/x86_64-unknown-linux-gnu/debug/laravel-rust-skeleton \
serve --host 127.0.0.1 --port 18080
Once the server is ready, send these two requests from a second terminal. Both use Accept: application/json so that the missing route returns JSON.
# Check the new route
curl -i --noproxy '*' -H 'Accept: application/json' \
http://127.0.0.1:18080/hello-rust
# Check the response for a missing route
curl -i --noproxy '*' -H 'Accept: application/json' \
http://127.0.0.1:18080/pilot-route-not-found
The /hello-rust response is plain text because the handler returns a string:
HTTP/1.1 200 OK
Content-Type: text/plain; charset=utf-8
Content-Length: 24
Hello from Laravel Rust!
The missing /pilot-route-not-found returns JSON with status 404:
HTTP/1.1 404 Not Found
Content-Type: application/json
Content-Length: 23
{"message":"Not Found"}
Neither response body has a trailing newline. Press Ctrl+C in the first terminal to stop the server.
Summary
On x86_64 Linux, the v0.1.2 skeleton with laravel-rust 0.1.4 built successfully and returned 200 and 404 responses. This route did not require Node.js, npm, a frontend build, migrations, a running database, Redis, SMTP, or a queue worker. A full application may need these components; I did not test the default welcome page or HTML 404 response without frontend assets.
For practice, add another GET route with a different path and text, then rebuild and test it. A future lesson will cover the Rust basics PHP developers need.