Creating your first Laravel Rust app
Part 2 · Laravel Rust. Install the Laravel CLI, create the Rusty Bean Café app, set up a database and see it running in your browser.
In the last lesson you met Laravel Rust. Now you’ll install it and get the Rusty Bean Café website running on your own computer. By the end you’ll have a real web app at http://127.0.0.1:8000, rebuilding itself every time you save a file.
Every command in this lesson comes from the official Laravel Rust installation guide (opens in new tab). If something looks different on your machine, that page is the source of truth.
What you need first
Laravel Rust needs three tools:
- Rust 1.99 or later. You installed Rust in Installing Rust.
- Node.js (the LTS, or “long-term support”, release). Your app’s front end, the part that runs in the browser, is built with JavaScript tools that run on Node.js.
- Git, which most computers already have.
If you installed Rust a while ago, update it:
rustup updateThis downloads the latest stable Rust. Check the version with rustc --version. It should say 1.99 or higher.
If you don’t have Rust at all, the official installer for macOS and Linux is:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | shOn Windows, download the installer from rustup.rs (opens in new tab) instead. For Node.js, grab the LTS installer from the Node.js download page (opens in new tab).
Install the Laravel CLI
A CLI (command-line interface) is a program you run by typing commands in your terminal. The Laravel CLI creates new apps and runs your app’s commands.
On macOS and Linux:
curl -fsSL https://laravel.com/install.sh | shOn Windows, in PowerShell:
powershell -ExecutionPolicy Bypass -c "irm https://laravel.com/install.ps1 | iex"Step by step:
curl -fsSL ...downloads Laravel’s install script.| sh(or| iexon Windows) runs it.- The script puts the
laravelcommand in~/.laravel/binand adds that folder to yourPATH, the list of folders your terminal searches for commands.
Open a new terminal window so it picks up the new PATH, then check the install:
laravel --versionThe output should start with Laravel CLI.
Warning
If you’ve used PHP Laravel before, you may already have an older laravel command from Laravel Herd or Composer. If laravel --version doesn’t start with Laravel CLI, the old one is being found first. Run which -a laravel (macOS/Linux) to list every laravel on your system, then move the ~/.laravel/bin line in your shell profile (such as ~/.zshrc) below the Herd or Composer lines. The installation guide (opens in new tab) has the full steps.
Create the café app
Go to the folder where you keep your projects and run:
laravel new rusty-beancd rusty-beanlaravel new asks which language you’d like to use. Choose Rust. To skip the question, for example in a script, pass the --rust flag:
laravel new rusty-bean --rustBehind the scenes, the CLI:
- Downloads a fresh app into a
rusty-beanfolder. - Creates a
.envfile for your settings. - Installs the front-end dependencies (your app comes with Inertia, React, TypeScript, Tailwind and Vite Plus).
- Compiles the app, so the first run starts right away.
The first compile can take a few minutes because Cargo builds every dependency from source. Grab a coffee, it’s on theme.
Your secret key
The CLI also creates an encryption key and saves it as APP_KEY in .env. Laravel uses it to lock your cookies and sessions so nobody can tamper with them.
Important
.env holds secrets such as APP_KEY and database passwords. Never commit it to Git or share it. Your new app’s .gitignore already leaves it out.
One more detail: whatever you name your project, its library is always called app. So when you import your own code, the paths start with app::, as in use app::models::User.
Set up a database
A database is where your app stores its data permanently: users, menu items, orders. Even a brand-new app needs one, because it keeps logged-in users and background jobs there.
New apps expect PostgreSQL, a popular database server. Your .env file starts with these lines:
DB_CONNECTION=postgresDATABASE_URL=postgres://postgres@127.0.0.1/laravelThese mean: “use PostgreSQL, running on this computer, with a database called laravel.” If you don’t have PostgreSQL yet, DBngin (opens in new tab) (macOS and Windows) or Postgres.app (opens in new tab) (macOS) can start one in a few clicks. Laravel recommends developing with the same database you’ll use in production.
The SQLite option
Prefer not to run a database server while you learn? Laravel Rust also supports SQLite, which keeps the whole database in one file. Two changes:
- In
Cargo.toml, find thelaravel-rustdependency and replace itsdatabase-postgresfeature withdatabase-sqlite. - Point
.envat a file:
DB_CONNECTION=sqliteDATABASE_URL=sqlite://storage/app/database.sqlite?mode=rwcThe ?mode=rwc part tells SQLite to create the file the first time your app connects (rwc stands for read, write, create).
Run the migrations
Migrations are Rust files that describe how to build your database tables. You’ll write your own in Migrations and the schema builder. For now, run the ones that come with the app:
laravel migrateThis creates the users, sessions and queue tables. If the database doesn’t exist yet, migrate offers to create it.
Run the app
Now the fun part:
laravel devlaravel dev starts three things at once:
- Your web server, the Rust program that answers requests.
- A queue worker, which runs background jobs (more on those in Queued jobs).
- Vite Plus, which serves your front-end files and reloads them as you edit.
Open your browser at http://127.0.0.1:8000 and you’ll see the welcome page. 127.0.0.1 means “this computer”, and 8000 is the port, like a door number on your machine.
Leave laravel dev running while you work. When you save a change to your Rust code or .env, the app rebuilds and restarts, and the browser refreshes once it’s back. Edits to front-end files hot-reload immediately. To stop it, press Ctrl+C in the terminal.
Tip
Rust rebuilds take a few seconds, unlike PHP where you just refresh. If the page seems stuck, look at the terminal running laravel dev. A compiler error there means the new version didn’t build, and the error tells you what to fix.
Ask your app what it can do
Your app has its own console commands, and you run them through laravel from anywhere inside the project. Try listing every route:
laravel route:listYou’ll see each URL your app answers, its HTTP method and the handler behind it. One route worth spotting is /up, the health check. It answers 200 (meaning “OK”) once your app has started, so hosting services can check that it’s alive.
To see every available command:
laravel listIf you’re ever somewhere without the laravel CLI installed, you can run the same commands through Cargo:
cargo run -- route:listThe -- tells Cargo “everything after this goes to my program, not to Cargo.”
Try it yourself
- With
laravel devrunning, visithttp://127.0.0.1:8000/upin your browser. What do you see? Then runlaravel route:listin a second terminal and find the/uproute. - Without looking back, write down the four commands that take you from “nothing installed except Rust” to “café app running in my browser” (assume PostgreSQL is already running).
Show solution
/upanswers with status200, which means the app is healthy. Don’t expect a pretty page. This route is meant for load balancers and uptime monitors, not people. Inlaravel route:listyou’ll find/upalongside the welcome page.- In order:
curl -fsSL https://laravel.com/install.sh | shlaravel new rusty-bean --rustlaravel migratelaravel dev(Remember to open a new terminal after installing the CLI, and to cd rusty-bean before laravel migrate.)
Recap
- Laravel Rust needs Rust 1.99+, Node.js and Git. The Laravel CLI installs with one command.
laravel new rusty-bean(choose Rust, or pass--rust) creates, configures and compiles a new app..envholds your settings and secrets, includingAPP_KEY. Never commit it.- New apps use PostgreSQL by default, and SQLite works too.
laravel migratecreates the starter tables. laravel devruns the server, a queue worker and Vite together athttp://127.0.0.1:8000.laravel route:listshows your routes.
What’s next
Your app is running, but what are all those folders? In Project structure we’ll tour the project so you know where every part of the café lives.
0 of 35 lessons complete