> ## Documentation Index
> Fetch the complete documentation index at: https://herd.laravel.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Laravel for Rust

# How to set up a Laravel for Rust application

Herd serves Laravel for Rust applications just like your PHP sites. Every Laravel for Rust application in a parked path is available via its `.test` domain, and Herd builds and starts it on demand when you open it in the browser. There are no commands to learn and no servers to keep running in a terminal.

## Requirements

Herd builds Laravel for Rust applications with your Rust toolchain. Open the settings, go to "Runtimes" → "Rust" and click "Install". You can find all details on the [Rust page](https://herd.laravel.com/docs/macos/technology/rust.md).

## Creating an application

Herd ships with the Laravel installer, which creates Laravel for Rust applications with the `--rust` flag:

```bash theme={null}
cd ~/Herd
laravel new my-rust-app --rust
cd my-rust-app
herd open
```

You can also create Laravel for Rust applications in the new application window. Once Rust is installed, the window lets you choose between PHP and Rust. You can describe your idea in a prompt and let a coding agent [build it for you](https://herd.laravel.com/docs/macos/herd-studio/build-with-ai.md), or leave the prompt empty to create a fresh application.

When Herd creates the application, it uses Herd's PostgreSQL service if you have one installed. Otherwise, it switches the application to SQLite and runs the migrations for you.

## Cloning an existing application

Click "Clone Repository" in the new application window to clone an existing Laravel for Rust application. Herd recognizes the application by the `laravel-rust` crate in its `Cargo.toml` and prepares a checklist for it. Herd installs Rust if it's missing, offers to compile the application right away, generates the application key, runs the migrations and connects the services that the `.env` file asks for.

If you clone the repository in your terminal instead, the application works as soon as it's in a parked path. Herd builds it on the first visit.

## How Herd serves Laravel for Rust applications

Herd serves a site as a Laravel for Rust application when its `Cargo.toml` names the `laravel-rust` crate as a dependency. Other Rust projects, like libraries or command line tools, aren't served. A site with a PHP front controller, like `artisan` or `public/index.php`, stays a PHP site even if it contains a Rust crate.

When you open the site in your browser, Herd starts the application on a port of its own and nginx passes all requests for the `.test` domain to it:

* If the application has a `dev` script in its `package.json` and its `node_modules` are installed, Herd runs `laravel dev`. This starts the server, a queue worker and Vite. The server rebuilds and restarts when you change your Rust code, `Cargo.toml` or `.env`, and Vite hot-reloads your frontend.
* Otherwise, Herd runs `cargo run`.

The first start compiles the application and all of its dependencies, which can take a few minutes. Your browser shows what the build is doing while you wait, and the full output if the build fails. After that, the application starts in a second or two.

Herd stops the application when it didn't receive a request for five minutes, and starts it again with the next request. Laravel for Rust applications run without [Herd Studio](https://herd.laravel.com/docs/macos/herd-studio/overview.md), so they also work if you turned it off.

> [!NOTE]
>
> If Herd runs your application with `cargo run`, it doesn't pick up code changes on its own. Stop the application with `herd processes:stop app` or the stop button in the Applications window, and the next request builds and starts it again.

## Managing the application

The [Applications window](https://herd.laravel.com/docs/macos/sites/managing-sites.md) lists Laravel for Rust applications with all your other sites. Instead of the PHP version, the inspector shows a "Dev server" row with the command that Herd runs, its current state and the build progress. You can start, stop and restart the application there and look at its output.

You can do the same in your terminal. Run these commands in the application's directory:

```bash theme={null}
# Show the application, its command, its folder and its state
herd processes

# Show the output of the application and its build
herd processes:output app

# Stop and start the application
herd processes:stop app
herd processes:start app
```

## Running commands

Laravel for Rust applications don't use `php artisan` or Composer. Run your console commands with the `laravel` CLI from the application's directory, or through Cargo:

```bash theme={null}
laravel migrate
laravel make:migration create_posts_table
laravel route:list

# The same with Cargo
cargo run -- migrate
```

## Services

[Herd Pro](https://herd.laravel.com/checkout) users can connect their Laravel for Rust applications to Herd's [services](https://herd.laravel.com/docs/macos/herd-pro-services/services.md). Select the application in the Applications window and pick a service in the "Services" section of the inspector, or use the `herd site:services` command. Herd writes the keys that Laravel for Rust reads, like `DATABASE_URL` and `REDIS_URL`, to your `.env` file. Learn more in [Per-Site Services](https://herd.laravel.com/docs/macos/herd-pro-services/per-site-services.md#laravel-for-rust).

Laravel for Rust only compiles the drivers that you enable as Cargo features of the `laravel-rust` crate. Make sure that your `Cargo.toml` enables the feature for every service that your application uses:

| Service | Cargo feature |
| - | - |
| SQLite | `database-sqlite` |
| MySQL, MariaDB | `database-mysql` |
| PostgreSQL | `database-postgres` |
| Redis, Valkey | `redis` |
| Herd's mail server | `ses` |
| MinIO, RustFS | `s3` |
| Meilisearch, Typesense | `search` |

Laravel for Rust has no driver for MongoDB. Laravel Reverb, MinIO and RustFS use the same `.env` keys as in a PHP application.

When you copy the `.env` values of a service in the settings, a dropdown lets you choose between PHP and Rust, and Herd shows the matching keys and the Cargo feature that the service needs.

## Testing emails

Laravel for Rust sends emails with its SES mailer instead of SMTP. Herd's mail server accepts these emails as well, so you can [inspect them](https://herd.laravel.com/docs/macos/herd-pro-services/mail.md) like the emails of your PHP applications. Add these values to your `.env` file and enable the `ses` feature of the `laravel-rust` crate:

```bash .env theme={null}
MAIL_MAILER=ses
AWS_ENDPOINT_URL_SESV2=http://127.0.0.1:2304
AWS_DEFAULT_REGION=us-east-1
AWS_ACCESS_KEY_ID=herd
AWS_SECRET_ACCESS_KEY=secretkey
SES_CONFIGURATION_SET="${APP_NAME}"
```

Herd uses `SES_CONFIGURATION_SET` as the name of the inbox, like `MAIL_USERNAME` for PHP applications. The mailer needs the AWS credentials to sign its requests, but they don't have to be real ones. The port of `AWS_ENDPOINT_URL_SESV2` is the port of Herd's internal API server, which is `2304` by default. To copy the values for your machine, click the copy button in the toolbar of the Mails window and select "Copy for Rust".

## HTTPS

You can [secure](https://herd.laravel.com/docs/macos/sites/securing-sites.md) a Laravel for Rust application like any other site. When you do, Herd also updates the `vite.config` of the application, so Vite uses Herd's certificate and serves your assets via the site's domain instead of `http://localhost:5173`. When you unsecure the site, Herd restores the previous values. A running Vite restarts on its own.

## Herd Studio

[Herd Studio](https://herd.laravel.com/docs/macos/herd-studio/overview.md) works with Laravel for Rust applications. Herd tells the coding agent that the site is a Laravel for Rust application, which commands it runs with and how to rebuild it, so the agent doesn't try to use `php artisan` or Composer. The Studio badge shows the application as the site's dev stack, where you can follow its output and start or stop it.

## Customizing how Herd starts the application

If your application lives in a subdirectory of your repository, or needs a different command, add an `app_server` section to the site's `herd.yml` file. See [Configuring app servers](https://herd.laravel.com/docs/macos/sites/herd-yaml.md#configuring-app-servers) for all options.
