# Deploying Rust applications

> Deploy single-binary Rust applications on Ploi Cloud: connect a Cargo.toml repo, build with cargo build --release, serve with the binary. APP_KEY is set automatically.

Rust on Ploi Cloud
-----------------

Ploi Cloud supports single-binary Rust applications. Your repository holds a `Cargo.toml` and a committed `Cargo.lock`; the platform builds the binary in a separate build stage, ships it to the runtime image together with your `public/` and `resources/views/`, and serves it as PID 1. Every other part of the deployment pipeline works the same as for any other application type.

### Requirements

- A Cargo workspace or crate that produces exactly one executable.
- A committed `Cargo.lock` so the build is reproducible.
- If your crate produces several executables, build exactly one with `cargo build --release --bin <name>` and set `build_commands` to that in your application settings.

### The build

The build stage runs in the `base/rust:1-trixie` image. It copies your repository, installs Node when a Node version is set (see below), runs your build commands (`cargo build --release` by default), and fails the build if the result contains anything but one executable in `target/release`. The build stage never ships in the final image.

The final image is the same mirrored serversideup runtime every other application type uses (`base/serversideup-php:<php>-fpm-nginx`). It runs as PID 1 (the shell wrapper execs into it), and it does not carry a Rust toolchain, a PHP extension install, or any apt step.

### Building a frontend

If your repository contains a `package.json` with a `build` script, the platform detects it when the application is created and on every deploy, and adds `npm ci && npm run build` to the build commands (before the Rust build) and sets Node 24. Pure Rust repositories without a `package.json` are unaffected: no Node install runs and the build behaves as before.

You can edit or remove the commands in your application settings. The platform only adds them when the current build commands are empty or exactly `cargo build --release`, so your own edits are never overwritten. Set the Node version to `none` to opt out, or delete the commands; the platform skips the detection when the Node version is set to anything, including `none`.

Applications created from an upload source get no automatic detection: add the commands by hand.

### Runtime files

The final image ships the built binary together with `public/` and `resources/views/` (when those directories exist) in `/var/www/html`, plus a `storage/` directory. The container runs with `WORKDIR /var/www/html`, so the binary reads its views and assets relative to that directory.

A database-backed app such as the official Laravel for Rust starter also needs a `DATABASE_URL` (Postgres by default) for anything database backed, and it runs migrations via an init command such as:

```bash
/var/www/html/app migrate --force
```

The welcome page itself needs no database.

### Start command

The default start command is `/var/www/html/app serve`. The container is stopped with SIGTERM and the binary receives it directly, so shutdown is fast and clean (no 10-second grace period). The binary serves on port 8080 by default. You can change the start command in your application settings if your binary exposes a different command.

The baked environment is `SERVER_HOST=0.0.0.0` and `SERVER_PORT=8080`. Setting your own `SERVER_HOST` or `SERVER_PORT` variables (in your application environment variables) overrides the baked values. A changed port means the readiness probe, which targets 8080, will not match. Change the port setting and the app port to stay in step.

### APP_KEY

A new Rust application automatically gets an `APP_KEY` secret in the `base64:` form (32 random bytes). The crate reads the key from this secret at runtime and encrypts cookies, sessions, and any other data that needs it. Without a valid key, every page returns a 500. To regenerate it, use the platform secret editor or the binary command `key:generate --show`.

The crate can also produce that key itself with:

```bash
cargo run -- key:generate --show
```

### APP_URL

A new Rust application automatically gets an `APP_URL` secret set to its app URL, e.g. `https://your-app.test.ploi.it`. The crate reads it at runtime and rejects any request whose Host does not match the configured URL with a 400 Bad Request. Keep `APP_URL` in step with the domain your app is served from: when you point the app at a custom domain, update the `APP_URL` secret to match the new domain.

### Default health check path

The default health check path for a Rust application is `/up`. Point this at an endpoint that returns a 200 when the application is healthy and keeps the default only if your application actually serves it. If your application has no `/up` route, the readiness probe fails and the app is treated as unhealthy. You can change the health check path in your application settings to whatever your binary exposes.

### PORT and health checks

The platform targets port 8080 for the service, the ingress, and the readiness and liveness probes. If you run the binary on a different port, update the port setting as well.

### Logs

`LOG_CHANNEL=stderr` is set for every application by the platform. What the crate does with it is unverified: the local checks did not exercise it, so treat the exact behavior as unknown rather than confirmed. The documented knobs are `LOG_CHANNEL` (`stderr` is one of the channels it accepts), `RUST_LOG` or `LOG_LEVEL`, and `LOG_FORMAT`.

### What is not supported yet

- Workers, scheduler, and Reverb are not wired up for Rust applications. They are planned separately.
- Cargo dependency caching across builds is not yet verified in the build pipeline and is not configured.
"

## Frequently asked questions

### How do I deploy a Rust application on Ploi Cloud?

Connect your Git repository, pick the Rust application type, and deploy. The platform builds the binary with cargo build --release and copies it into the runtime image. No start command is required: the platform uses /var/www/html/app serve by default.

### Does Ploi Cloud generate the APP_KEY for a Rust app?

Yes. A new Rust application gets an APP_KEY secret automatically, in the base64: form (32 random bytes). Every page returns a 500 without it, so keep the secret.

### What is the default health check path for a Rust app?

Health check path /up. If your application has no /up route, the readiness probe fails and the app is unhealthy.

### Does Ploi Cloud install a Rust toolchain in the final image?

No. The build stage uses base/rust:1-trixie to compile; the runtime image carries the binary plus any public/ and resources/views/ your repository has, and no Rust toolchain.
