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.Creating an application
Herd ships with the Laravel installer, which creates Laravel for Rust applications with the--rust flag:
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 thelaravel-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 itsCargo.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
devscript in itspackage.jsonand itsnode_modulesare installed, Herd runslaravel dev. This starts the server, a queue worker and Vite. The server rebuilds and restarts when you change your Rust code,Cargo.tomlor.env, and Vite hot-reloads your frontend. - Otherwise, Herd runs
cargo run.
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 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:Running commands
Laravel for Rust applications don’t usephp artisan or Composer. Run your console commands with the laravel CLI from the application’s directory, or through Cargo:
Services
Herd Pro users can connect their Laravel for Rust applications to Herd’s services. Select the application in the Applications window and pick a service in the “Services” section of the inspector, or use theherd 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.
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:
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 like the emails of your PHP applications. Add these values to your.env file and enable the ses feature of the laravel-rust crate:
.env
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 a Laravel for Rust application like any other site. When you do, Herd also updates thevite.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 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 usephp 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 anapp_server section to the site’s herd.yml file. See Configuring app servers for all options.