Web app deploy: host app & database without servers

By Kate Baker
Web app deploy: host app & database without servers

A manual web app deploy usually fails in one of a few predictable ways. Someone runs git pull on the server but forgets npm run build, so production serves a stale bundle. A migration runs halfway and the app crashes on a missing column. The VPS reboots for a kernel update and Postgres does not come back up. Every one of these ends the same way: an hour or more of downtime and a few awkward emails to customers.

None of that is about your code. It is about the steps between "it works on my machine" and "it is running for users". This guide walks through what those steps are, how to prepare the three most common MVP stacks (Next.js, FastAPI, and Laravel) so they deploy cleanly, and how to host the app, database, and file storage without running a server yourself.

What a production web app deploy actually involves

Strip away the tooling and every web app deploy does the same six things:

  1. Build the code into something runnable: a bundle, a compiled binary, a Docker image.
  2. Configure it with environment-specific values: database URL, API keys, secrets.
  3. Migrate the database schema to match the new code.
  4. Start the new version and check it is healthy.
  5. Route traffic to it over HTTPS.
  6. Retire the old version.

On a self-managed VPS, you own each step, plus the things around them: the reverse proxy (Nginx or Caddy), TLS certificates, OS updates, database backups, disk space, and restarts after a crash.

On a managed platform, steps 1, 4, 5, and 6 happen automatically on every git push. You still own step 2 (setting the right variables) and step 3 (deciding how migrations run). This is the part people underestimate, so most of this guide is about making your app ready for it.

The three rules that make any app easy to deploy

Before touching framework specifics, check your app against these rules. They come from the Twelve-Factor App methodology, and they are the difference between a deploy that "just works" on a platform and one that fights it.

1. Read all config from environment variables. No config.prod.json committed to the repo, no values hardcoded for production. Database URLs, API keys, and feature flags come from the environment.

2. Keep the app stateless. Do not write user uploads, sessions, or caches to the local filesystem. On any platform that can scale or restart your app, local disk is temporary. Uploads go to object storage, sessions go to the database or Redis.

3. Listen on the port you are given. Platforms usually pass a PORT variable. Bind to 0.0.0.0 on that port, not localhost:3000.

If your app follows these three, the rest is mostly framework configuration.

Preparing a Next.js app

Next.js can run in several ways. For hosting on a container platform, the standalone output is the most efficient. It produces a minimal server.js plus only the node_modules files actually used.

Enable it in next.config.js (or next.config.ts):

/** @type {import('next').NextConfig} */
const nextConfig = {
  output: "standalone",
};

module.exports = nextConfig;

A Dockerfile that uses it:

# syntax=docker/dockerfile:1
FROM node:24-slim AS deps
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm ci

FROM deps AS build
COPY . .
RUN npm run build

FROM node:24-slim AS runtime
WORKDIR /app
ENV NODE_ENV=production \
    PORT=3000 \
    HOSTNAME=0.0.0.0
COPY --from=build /app/.next/standalone ./
COPY --from=build /app/.next/static ./.next/static
COPY --from=build /app/public ./public
USER node
EXPOSE 3000
CMD ["node", "server.js"]

Next.js gotchas that cause broken deploys:

  • NEXT_PUBLIC_* variables are inlined at build time. If you set NEXT_PUBLIC_API_URL only at runtime, the browser bundle will not see it. Make sure the variable is available during the build, not only when the container starts.
  • The standalone output does not copy public/ or .next/static. The two extra COPY lines above are required, or you get 404s on every image and CSS file.
  • Image optimization needs sharp for good performance in production. Recent Next.js versions use it automatically when it is installed; add it to your dependencies if it is not already there.
  • Server-side database calls need a pooled connection. Every server instance holds its own pool, so keep pool sizes small (5–10) and scale instances rather than pool size.

Preparing a FastAPI app

FastAPI apps are simpler to package. The main decisions are the ASGI server and the number of workers.

# syntax=docker/dockerfile:1
FROM python:3.13-slim
ENV PYTHONDONTWRITEBYTECODE=1 PYTHONUNBUFFERED=1
WORKDIR /app

COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

COPY . .
RUN useradd --create-home app
USER app

ENV PORT=8000
CMD ["sh", "-c", "exec uvicorn app.main:app --host 0.0.0.0 --port ${PORT} --workers 2 --proxy-headers --forwarded-allow-ips='*'"]

Why these flags:

  • --host 0.0.0.0 so the platform's router can reach the app.
  • --proxy-headers and --forwarded-allow-ips so FastAPI sees the real client IP and https scheme from the platform's load balancer. Without them, redirects generated by the app may point to http://. Only trust all forwarded IPs when the app is not reachable directly from the internet, which is the normal case behind a platform router.
  • exec so Uvicorn replaces the shell as the main process and receives shutdown signals directly.
  • --workers 2 is a reasonable start for a small instance. More workers means more memory. On a platform with automatic scaling, it is usually better to keep workers low and add instances.

Read config with pydantic-settings, so a missing variable fails fast at startup instead of at the first request:

from pydantic_settings import BaseSettings

class Settings(BaseSettings):
    database_url: str
    s3_endpoint_url: str
    s3_bucket: str
    secret_key: str

settings = Settings()

For migrations, Alembic is the standard with SQLAlchemy. Run alembic upgrade head as a release step, not inside the app's startup code. If you run migrations at startup and you have three instances, three processes race to apply the same migration.

Preparing a Laravel app

Laravel has more moving parts: a web process, usually a queue worker, and often a scheduler. Each should run as its own service from the same image.

A compact option in 2026 is FrankenPHP, which bundles PHP and a web server in a single process, so you do not need to configure Nginx and PHP-FPM separately:

# syntax=docker/dockerfile:1
FROM composer:2 AS vendor
WORKDIR /app
COPY composer.json composer.lock ./
RUN composer install --no-dev --no-scripts --no-autoloader \
    --prefer-dist --no-interaction --ignore-platform-reqs
COPY . .
RUN composer dump-autoload --optimize --no-dev

FROM dunglas/frankenphp:1-php8.4
RUN install-php-extensions pdo_pgsql redis opcache
WORKDIR /app
COPY --from=vendor /app ./
ENV SERVER_NAME=:8080
EXPOSE 8080

SERVER_NAME=:8080 tells FrankenPHP to serve plain HTTP on port 8080 and leave TLS to the platform. The composer stage installs dependencies with --ignore-platform-reqs because the Composer image does not have your PHP extensions; the final FrankenPHP stage is where pdo_pgsql and friends actually get installed.

Then define separate processes from the same image:

ProcessCommand
WebDefault image command (FrankenPHP serving public/)
Queue workerphp artisan queue:work --tries=3 --max-time=3600
Schedulerphp artisan schedule:work
Release stepphp artisan migrate --force && php artisan config:cache && php artisan route:cache

Laravel-specific gotchas:

  • Set FILESYSTEM_DISK=s3 and the AWS_* variables so uploads go to object storage. For S3-compatible providers you usually also need AWS_ENDPOINT and AWS_USE_PATH_STYLE_ENDPOINT=true.
  • Do not run config:cache at image build time if your environment variables are only available at runtime, because it bakes the current (empty) values into the cache.
  • Sessions and cache should use database or redis, not file.
  • APP_KEY must be identical across all instances, otherwise encrypted cookies fail on every other request.

Containerized apps in any other stack

If you use Go, Rails, Elixir, or anything else, the same pattern holds. A Dockerfile that:

  • builds in one stage and runs in a slim final stage,
  • binds to 0.0.0.0:$PORT,
  • runs as a non-root user,
  • starts the process in exec form so it receives SIGTERM,

will run on essentially any container platform. Expose a /healthz endpoint that checks the database connection, so the platform can tell whether a new version actually works before sending it traffic.

The database: managed, not installed

The most painful outages in self-hosted setups are database outages. Disks fill up with WAL files and logs, postgresql.conf is never tuned, and the backup script turns out to have been failing silently for a month.

A managed database takes the operational part off your plate. What you still need to get right:

  1. Use a connection string from the environment. Most frameworks accept a single DATABASE_URL.
  2. Size your connection pools. Total connections = instances × workers × pool size. Keep that under the database's connection limit. Add a pooler if you scale out a lot.
  3. Run migrations as a release step, once per deploy, before the new version receives traffic.
  4. Write backward-compatible migrations. During a rolling deploy, the old and new versions briefly run at the same time. Add a column in one deploy, start using it in the next, drop old columns later.
  5. Test a restore at least once. A backup you have never restored is a hope, not a backup.

File storage: S3-compatible with a CDN

User uploads, generated PDFs, and large static assets belong in object storage. Almost every language has a mature S3 client, and "S3-compatible" means you point the same client at a different endpoint.

A Node.js example with the AWS SDK v3:

import { S3Client, PutObjectCommand } from "@aws-sdk/client-s3";

const s3 = new S3Client({
  region: process.env.S3_REGION ?? "auto",
  endpoint: process.env.S3_ENDPOINT,
  forcePathStyle: true,
  credentials: {
    accessKeyId: process.env.S3_ACCESS_KEY_ID,
    secretAccessKey: process.env.S3_SECRET_ACCESS_KEY,
  },
});

await s3.send(new PutObjectCommand({
  Bucket: process.env.S3_BUCKET,
  Key: `avatars/${userId}.png`,
  Body: fileBuffer,
  ContentType: "image/png",
}));

Serve public files through the CDN URL rather than streaming them through your app. Your app instances stay free for actual requests, and users get files from a location close to them.

Putting it together on Granite.so

Once the app follows the rules above, the hosting side becomes short. On Granite.so the flow looks like this:

  1. Connect your Git repository and choose the branch to deploy. Granite.so builds from your Dockerfile, or you can point it at a prebuilt Docker image.
  2. Create a managed database and copy its connection string into the app's DATABASE_URL environment variable.
  3. Create an S3-compatible storage bucket and add its endpoint and credentials as environment variables. Public files are served through the built-in CDN.
  4. Set the rest of your environment variables: secrets, API keys, APP_KEY for Laravel, NEXT_PUBLIC_* values for Next.js.
  5. Push to your branch. Every push triggers an automatic rebuild and deploy. HTTPS and routing are handled for you, and automatic scaling adds capacity when traffic grows.

There is no Nginx config to write, no certificates to renew, and no Kubernetes YAML. The Hobby plan starts at $9 per month and includes $15 in monthly usage credits, which covers a typical MVP with an app, a small database, and storage. Check the pricing page for current details.

Honest trade-offs

A managed platform is not the right choice for everyone:

  • Raw cost: a bare VPS is cheaper per unit of CPU and RAM. You are paying to not do the operations work.
  • Control: you cannot tune kernel parameters or install arbitrary system daemons alongside your app.
  • Long-running or unusual workloads, like GPU jobs or very large background processing, may fit better elsewhere.

For most MVPs, though, the bottleneck is not compute cost. It is the hours spent on DevOps firefighting instead of features.

A pre-deploy checklist

Before your first push to production, run through this list:

  • All config comes from environment variables
  • App binds to 0.0.0.0:$PORT
  • No writes to local disk for uploads or sessions
  • Health check endpoint that verifies the database connection
  • Migrations run as a release step, and are backward compatible
  • Connection pool sizes fit the database connection limit
  • Build-time variables (like NEXT_PUBLIC_*) are set for the build
  • Error tracking and logs are wired up before real users arrive

Get these right once, and every web app deploy after that is just git push. If you want to skip the server setup entirely, connect your repo to Granite.so and ship your next release without logging into a single machine.

Keep reading

More posts tagged “Tutorials”.
Be first in line for updates
and special pricing
Get early access to new features and exclusive discounts delivered straight to your inbox