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

# Rust (beta)

> Run any Rust web app that builds with Cargo. The preset compiles it on the pod and runs the program under systemd.

The Rust preset runs any Rust web app that builds with Cargo, has `Cargo.toml` at the top level and listens on `0.0.0.0:8080`. It works with frameworks like Axum, Actix Web and Rocket. Laravel Rust is supported too and gets [extra setup](#laravel-rust). Your project is built on the pod in release mode, and the program runs as a systemd service.

> [!NOTE]
>
> The Rust preset is in **beta**. It needs the **Build** plan (2 GB of memory) or higher, because compiling Rust takes more memory than Launch has. It isn't available on a [free trial pod](https://docs.instapods.com/mcp/trial.md).

## What's Included

| Component | Version | Details |
| - | - | - |
| **Rust toolchain** | 1.100 (via rustup) | In `/home/instapod/.cargo/bin`. A `rust-toolchain.toml` in your repo selects another version |
| **Node.js** | 24 | For front-end builds |
| **Build tools** | Latest | `build-essential`, `pkg-config`, `cmake`, `libssl-dev` |
| **systemd** | - | Process manager (`app` service) |
| **git** | Latest | Version control |

## How Your App Runs

* **App root**: `/home/instapod/app`. Your `Cargo.toml` must be here, at the top level.
* **App port**: 8080
* **Program**: `/home/instapod/.app-bin/app`, copied there after each successful build
* Runs as the `instapod` user, starts on boot, restarts on a crash

These variables are set for your app: `PORT=8080`, `HOST=0.0.0.0`, `ROCKET_PORT=8080` and `ROCKET_ADDRESS=0.0.0.0`.

> [!WARNING]
>
> Your app **must** listen on `0.0.0.0`, port 8080. An app on `127.0.0.1` or `localhost` can't be reached from the public URL.

## The Build Step

Every deploy (git, `instapods deploy`, ZIP upload, `pods reload`) runs these steps:

1. **Front end.** When `package.json` has a `build` script, its packages are installed and the script runs. npm, pnpm, Yarn and Bun are supported.
2. **Compile.** `cargo build --release`.
3. **Install.** The new program is copied into place and the service restarts.

> [!NOTE]
>
> If any step fails, the deploy fails with the error and your previous program keeps running.

### How long it takes

A first build compiles every crate you use. On the Build plan, a small Axum app takes about 35 seconds. Laravel Rust takes **about 5 minutes**, and can take up to 10. Later deploys reuse the `target/` folder and usually finish in under a minute. One build may take up to 30 minutes.

`target/` is kept between deploys. It is left out of backups, and it is emptied before a build when it passes 6 GB.

### Which program runs

The program is read from `Cargo.toml`. If your project builds several, name the one to run:

```toml theme={null}
[package]
name = "my-app"
default-run = "server"
```

In a workspace, also list that crate in `default-members`.

### Custom build command

You can replace the build in the pod's Git settings. End your command by copying the program to `/home/instapod/.app-bin/app.new`. InstaPods then puts it in place and restarts the app:

```bash theme={null}
cargo build --release --features prod && cp target/release/server /home/instapod/.app-bin/app.new
```

## Deploying Your App

```bash theme={null}
# From a folder on your computer
instapods deploy my-rust-app --preset rust --plan build

# From GitHub
instapods deploy --repo https://github.com/owner/repo --preset rust --plan build
```

A repo with a `Cargo.toml` at its top level is detected as Rust. A repo that also has a `package.json` or `composer.json` is Rust when it depends on a web framework such as Axum, or has a program to run (`src/main.rs`, `[[bin]]` or `default-run`). A Node package with a Rust add-on (napi-rs, Neon) and a Tauri app stay Node.js, and a Python package built with maturin stays Python. Pass `--preset` to override.

> [!NOTE]
>
> `instapods deploy` from a folder detects Rust from CLI v1.19.0. On an older CLI, pass `--preset rust`.

### Example App

```toml theme={null}
# Cargo.toml
[package]
name = "hello"
version = "0.1.0"
edition = "2024"

[dependencies]
axum = "0.8"
tokio = { version = "1", features = ["full"] }
```

```rust theme={null}
// src/main.rs
use axum::{Router, routing::get};

#[tokio::main]
async fn main() {
    let port = std::env::var("PORT").unwrap_or_else(|_| "8080".into());
    let app = Router::new().route("/", get(|| async { "Hello from InstaPods!" }));
    let listener = tokio::net::TcpListener::bind(format!("0.0.0.0:{port}")).await.unwrap();
    axum::serve(listener, app).await.unwrap();
}
```

## Laravel Rust

An app that depends on the `laravel-rust` crate gets its settings written to `.env` on each deploy:

| Setting | Value |
| - | - |
| `SERVER_HOST`, `SERVER_PORT` | `0.0.0.0` and `8080`, always |
| `APP_ENV`, `APP_DEBUG`, `APP_URL` | `production`, `false` and your pod's URL, when not set |
| `APP_KEY` | Generated once with `key:generate`, then kept |
| `DATABASE_URL` | Your pod's database, when not set |

When `Cargo.toml` turns on `database-postgres` or `database-mysql` and the pod has no such database, it is installed on the first deploy. `migrate --force` runs after each build when `DATABASE_URL` is set, but not on a rollback. If a migration fails, the deploy fails and the old program keeps running. Set your own release command in the pod's Git settings to replace it.

> [!WARNING]
>
> Laravel Rust answers **400 Bad Request** to any domain except the one in `APP_URL` and its subdomains. When you add a custom domain, run `instapods env set my-rust-app APP_URL=https://example.com`. The app restarts with the new value. The pod's own `instapods.app` address then answers 400. Once your domain is connected to the pod, `instapods deploy` and `pods reload` check your domain instead. To serve several domains, list them with `trust_hosts` in your app.

### Queue worker

A worker runs your queued jobs. It is a systemd service called `app-worker` that runs `queue:work`. Your next deploy or reload sets it up, and it restarts whenever the app does.

| Your setup | Worker |
| - | - |
| `QUEUE_CONNECTION` is not set, or `database`, and the pod has a database | Runs |
| `QUEUE_CONNECTION` is `redis`, `sqs` or another queue | Runs |
| `QUEUE_CONNECTION` is `sync` or `discard` | Not needed, so not set up |
| You already run your own `queue:work` systemd service | Yours is kept. Restart it yourself after a deploy |

```bash theme={null}
instapods logs my-rust-app -s app-worker
instapods exec my-rust-app -- sudo systemctl disable --now app-worker   # turn it off
```

Scheduled tasks (`schedule:work`) are not started for you.

## Adding a Database

```bash theme={null}
instapods services add my-rust-app --service postgresql
instapods services creds my-rust-app --service postgresql
```

## Limits

* The Cargo project must be at the top level of the repo. The subdirectory setting (`--subdir`) doesn't change that.
* A `Dockerfile` in the repo is not used.
* Crates that need a system library other than OpenSSL don't build until you install it in the pod with `apt-get`.

## Viewing Logs

```bash theme={null}
instapods logs my-rust-app -s app
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.