Payload CMS

Deploy a Payload CMS app

Run Payload 3 and its Next.js app as one server with managed Postgres or MongoDB, migrations applied on start and media in an S3 bucket. This guide goes from create-payload-app to a production deploy on Modelence.

Last updated /Tested with Payload 3.94.2, Next.js 16.4 and Node.js 22.23

To deploy Payload 3, build its Next.js app with npm run build, apply your migrations with payload migrate, and start it with npm start, with PAYLOAD_SECRET set, a Postgres or MongoDB database behind it and the media collection stored in an S3 bucket. On Modelence that's a modelence.config.json in the project and npx modelence@latest deploy, which builds the app on an official Node.js image and runs it as a managed container on AWS, in one of 17 regions, with managed MongoDB, Postgres and Redis next to it.

Since version 3, Payload installs into a Next.js app, so the admin panel at /admin, the REST and GraphQL APIs under /api and your own pages are the same server and deploy together. That makes Payload a regular Next.js deploy with two additions: a database the server reaches at runtime, and a migration step before it starts. We built the app below with the Postgres adapter, ran the production server against MongoDB locally, and ran payload migrate against SQLite, all with Payload 3.94.2 and Next.js 16.4 on Node.js 22. The Next.js guide covers the parts that aren't specific to Payload.

Payload on Modelence at a glance

How it runs
next build compiles the admin panel, the APIs and your pages into one app, and next start serves them on the PORT Modelence sets
Database
Managed Postgres through the Postgres adapter, or managed MongoDB through the MongoDB adapter
Migrations
payload migrate runs as the first start command, so each deploy applies new migrations before the server starts
Secret
PAYLOAD_SECRET signs logins and is set once per environment
Media
The official S3 storage plugin keeps uploads in S3, Cloudflare R2 or another S3-compatible bucket
Health check
A small /health route that runs one database query
Regions
17 AWS regions, with the app and its database in the same one

Before you start

  • Node.js 22 or newer and npm, since Payload 3.94 supports Node.js 22, 24 and 26
  • A bucket for media, on S3 with an access key that can write to it or on an S3-compatible service such as Cloudflare R2
  • A local Postgres or MongoDB for development, such as one in Docker
  • A Modelence account, which you can create for free. Managed Postgres needs a paid plan, from $20 a month with that amount included as usage
  • Optionally, Claude Code, Cursor or Codex, if you'd rather have your coding agent write the files and run the deploy

Create a Payload app

Create the app with Payload's CLI. It asks for a template, where blank gives you users, media and nothing else, and for the database adapter. Pick Postgres or MongoDB, the two databases this guide covers equally, and give it the connection string of your local database:

npx create-payload-app@latest my-payload
cd my-payload

The result is a Next.js app with Payload's routes under src/app/(payload), a src/payload.config.ts that lists collections and the database adapter, and a .env with DATABASE_URL and a generated PAYLOAD_SECRET. The generated package.json already has the scripts Modelence will run: build for next build, start for next start and payload for Payload's own CLI.

Run npm run dev and open http://localhost:3000/admin to create the first user and try the admin panel.

Turn schema changes into migrations

With Postgres, Payload in development mode pushes every change in your collections straight to the local database, which keeps iteration fast but leaves no record production could replay. Before you deploy a change, create a migration from it:

npm run payload migrate:create add-posts

This writes a TypeScript file with the SQL for the change to src/migrations, along with an index.ts that lists every migration. Commit them. In production, payload migrate runs the ones the database hasn't seen yet, each in its own transaction, and records them in a payload_migrations table. Create the first migration right after create-payload-app, before any deploy, so production gets its tables the same way.

With MongoDB there are no tables to create, so collection changes need no migration. You can still write migrations with migrate:create for data changes, such as filling in a new field on existing documents, and payload migrate runs them the same way.

Add a health route

Add a route handler that loads Payload and runs one query. Modelence calls it after each deploy and only sends traffic to a new container once it answers with a 2xx, so a container that can't reach the database never replaces a working one:

src/app/health/route.ts
import configPromise from '@payload-config'
import { getPayload } from 'payload'

export const dynamic = 'force-dynamic'

export const GET = async () => {
  const payload = await getPayload({ config: configPromise })
  // A cheap query, so the check fails if the database is unreachable
  await payload.count({ collection: 'users' })
  return Response.json({ status: 'ok' })
}

Add a database

  • MongoDBMONGODB_URI
  • PostgresDATABASE_URL
  • RedisREDIS_URL

Payload supports Postgres, MongoDB and SQLite through separate adapters, and Postgres and MongoDB both work as a managed database on Modelence. Each adapter reads a connection string, so the only change between them is the resource and the variable name.

Postgres. The config below creates a managed Postgres called main-db and passes its url output as DATABASE_URL, which the Postgres adapter in the generated payload.config.ts reads through pool.connectionString. The URL ends in ?sslmode=require, so connections use TLS without extra settings.

MongoDB. Declare a mongodb resource instead, as in the snippet after this section. It reaches the app as MONGODB_URI, so change the adapter line to mongooseAdapter({ url: process.env.MONGODB_URI || '' }), keep PAYLOAD_SECRET, and drop the DATABASE_URL entry.

{
  "resources": {
    // "web": the app's service, as in the deploy step
    "main-db": { "type": "mongodb" }
  }
}

Database variables reach the running container, not the build. The generated app builds without a database, since its routes are rendered for each request. If your own pages query Payload at build time, for example in generateStaticParams, mark them export const dynamic = 'force-dynamic' or have them return an empty list during the build, so next build doesn't need a connection.

modelence.config.json
{
  "resources": {
    // "web": the app's service, as in the deploy step
    "main-db": { "type": "postgres", "plan": "postgres-1gb" }
  },
  "env": {
    "DATABASE_URL": { "type": "resource", "resource": "main-db", "output": "url" }
  }
}

Store media in S3

The media collection in a new app saves uploads to a media folder in the project, and on Modelence each deploy starts from a fresh container. Install the official storage plugin and add it to src/payload.config.ts, so uploads and the image sizes Payload generates with sharp go to a bucket:

npm install @payloadcms/storage-s3

Keep the plugin on the same version as payload and the other @payloadcms packages. For Cloudflare R2 or another S3-compatible service, set S3_ENDPOINT to its endpoint, such as https://<account id>.r2.cloudflarestorage.com, and S3_REGION to auto. Payload still serves each file through /api/media/file/<name> and checks the collection's read access first, so the bucket can stay private. If your media is public and you'd rather link to the bucket or a CDN directly, add disablePayloadAccessControl: true to the collection's entry in the plugin.

src/payload.config.ts
import { s3Storage } from '@payloadcms/storage-s3'

export default buildConfig({
  // ...collections, editor, db and the rest of the generated config
  plugins: [
    s3Storage({
      collections: { media: true },
      bucket: process.env.S3_BUCKET || '',
      config: {
        credentials: {
          accessKeyId: process.env.S3_ACCESS_KEY_ID || '',
          secretAccessKey: process.env.S3_SECRET_ACCESS_KEY || '',
        },
        region: process.env.S3_REGION,
        endpoint: process.env.S3_ENDPOINT || undefined,
      },
    }),
  ],
})

Describe the app in modelence.config.json

Create modelence.config.json in the project root. It builds the app as a Node.js service, runs the migrations and then the server, and creates the database:

modelence.config.json
{
  "$schema": "https://cloud.modelence.com/schema/modelence.config.json?version=1",
  "resources": {
    "web": {
      "type": "service",
      "image": "node-22-slim",
      "build": { "commands": ["npm ci", "npm run build"] },
      "start": { "commands": ["npm run payload migrate", "npm start"] },
      "healthCheck": { "type": "http", "path": "/health", "gracePeriod": 120 }
    },
    "main-db": { "type": "postgres", "plan": "postgres-1gb" }
  },
  "env": {
    "NODE_ENV": { "value": "production" },
    "DATABASE_URL": { "type": "resource", "resource": "main-db", "output": "url" },
    "PAYLOAD_SECRET": { "type": "secret" },
    "S3_BUCKET": {},
    "S3_REGION": {},
    "S3_ACCESS_KEY_ID": { "type": "secret" },
    "S3_SECRET_ACCESS_KEY": { "type": "secret" }
  }
}

Check the config against your project

  • npm ci installs devDependencies such as TypeScript, which next build needs, and npm run build keeps the generated NODE_OPTIONS, including the larger memory limit for the build. Our build of the blank app took about 80 seconds and peaked under 2 GB of memory.
  • The two start commands run in order. npm run payload migrate applies new migrations and exits, and npm start runs next start, which keeps running and listens on 3000, the port Modelence gives a Node.js service. If a migration fails, the command exits with an error, the new container never starts, and the previous version keeps serving.
  • NODE_ENV=production has the default runtime scope, so the build still installs devDependencies, while payload migrate runs in production mode and never pushes schema changes the way development mode does.
  • PAYLOAD_SECRET and the S3 key are secrets with no value in the file. The deploy asks for them, and you can view or change them later in the dashboard under Environment variables, where every view is logged. Generate the secret with openssl rand -hex 32 rather than reusing the one in your local .env.
  • gracePeriod gives the first start 120 seconds, which covers creating every table on an empty database.

Check the build locally

Run what Modelence runs, with your local database in .env. Use another port if your dev server is still on 3000. /health should answer {"status":"ok"} and /admin should load the login page:

bash
npm ci && npm run build
NODE_ENV=production npm run payload migrate
PORT=3000 npm start
curl -i http://localhost:3000/health

Deploy

Run the deploy in the project folder:

npx modelence@latest deploy

The CLI opens the browser, where you sign in and pick or create the organization, app and environment. It then asks for PAYLOAD_SECRET, the bucket name, region and keys, and, on the first deploy of an environment, the AWS region where the container and database are created. The CLI uploads the project, builds it, and follows the rollout, which runs your migrations against the new database and waits for /health to pass.

Open /admin on the environment's URL and create the first user straight away, since anyone who reaches that form first gets the account. Your own domain goes under Domains in the dashboard. If your config sets serverURL, change it to match each environment, or leave it out so Payload uses the address each request came in on.

Let your coding agent do it

Paste Deploy using https://modelence.com/skill.md into Claude Code, Cursor or Codex in the project. The agent reads the Modelence docs, writes the config, adds the storage plugin and the health route, checks the build and deploys, and it asks you for the secret and the bucket details.

Production readiness

Never point the dev server at production

npm run dev with Postgres pushes schema changes to whatever database DATABASE_URL names, and Payload marks that database as changed outside migrations. The next payload migrate then stops to ask whether to continue, warning that data loss will occur, and in a deploy nobody can answer. Keep production's connection string out of local .env files, and test migrations against a copy of production data in the sandbox environment.

Add more containers

Media in S3 and data in the database leave nothing on the container, so you can raise the container count under Configure. Every new container runs payload migrate before it starts. When a deploy brings a new migration and several containers start at once, one applies it and another can fail on the same change, exit and be replaced, and the replacement finds the migration applied and starts. To avoid that churn, deploy migrations while running one container, or move payload migrate into its own short deploy.

Keep backups for the database and the bucket

Production databases on Modelence, Postgres or MongoDB, are backed up at least every six hours and kept for up to 12 months, and restores go through [email protected]. That covers documents, users and media metadata. The files themselves live in your bucket, so turn on bucket versioning if you want deleted or replaced files back too.

Upgrade all Payload packages together

Payload releases payload and every @payloadcms package with the same version number, and mixing versions fails at build or start. Upgrade them in one npm install, run npm run dev to check the admin panel, and create a migration if the release notes say the database schema changed. Deploy to the sandbox first. Payload 4 is in beta, so stay on 3.x in production until it's released.

Watch logs and memory

Output from payload migrate, Next.js and Payload's own logger shows on the environment's Logs page with no setup, so a failed migration is easy to find. Memory and CPU for each container are on the dashboard. The blank app used about 235 MB of memory after start in our test, so Small, with 0.5 vCPU and 1 GB at about $22 a month, is a reasonable first size, and image uploads, which sharp resizes in the same process, are what raise it.

Modelence vs Payload Cloud, Railway and Render for Payload

People choosing a host for Payload usually look at Payload Cloud, a Railway template, a Render web service and a VPS. The table uses each provider's official pages as of November 29, 2026.

OptionHow Payload runsData and mediaPrice
ModelenceYour Next.js app built on an official Node.js image, on AWS Fargate in 17 regionsManaged Postgres or MongoDB backed up at least every six hours; media in your S3 or R2 bucketFree plan; paid plans from $20 a month including $20 of usage, and managed databases need a paid plan
Payload CloudHosted by Payload, but deployment of new projects is pausedExisting projects keep runningNot open to new projects
RailwayA community template with Postgres and a Railway bucketDatabase and bucket on RailwayHobby $5 and Pro $20 a month including that much usage, then CPU and memory by use
RenderA Node.js web service you configure, since Render has no Payload guideRender Postgres, and a disk or a bucket for mediaHobby $0 or Pro $25 a month per workspace, plus instances from $7 a month
VPSNode.js or Docker on a server you manage, such as Hetzner CloudThe server's disk, with backups, TLS and updates handled by youHetzner servers from €5.49 a month before VAT

Payload Cloud was the managed option, and its pricing page now says deployment of new projects is paused. A VPS is the cheapest way to run one instance if you'll handle the server, the database and its backups yourself. Railway's template gets Payload running with a database and a bucket in a few clicks, and Render runs it as any Node.js web service. Modelence fits when the app should run on AWS with managed MongoDB, Postgres and Redis in the same region, migrations as part of every deploy and the whole setup in the repository. Railway alternatives and Railway vs Render compare those platforms in more depth, and Migrate from Railway covers moving an existing app.

Next steps

Frequently asked questions

How do I deploy Payload CMS?

Build the Next.js app with npm run build, run npm run payload migrate against the production database, and start it with npm start, with PAYLOAD_SECRET and the database connection string set and the S3 storage plugin handling media. On Modelence, a modelence.config.json lists those commands and creates the database, and npx modelence@latest deploy runs the rest.

Can I host Payload without Vercel?

Yes. Payload 3 is a Next.js app, and next start runs it on any Node.js server or container, with the admin panel, the APIs and your pages in one process. Running it as a long-lived server also suits Payload well, since database connections and the Payload instance stay warm between requests.

Does next build need a database connection for Payload?

Not for the app create-payload-app generates, which renders its routes for each request and built in our test with no database at all. Pages that query Payload during the build, for example to pre-render every post with generateStaticParams, do need one. Make those pages dynamic, or skip the query during the build, since database variables on Modelence reach the running app only.

Why does Payload say a table does not exist in production?

Because the schema was pushed to your local database by the dev server but never turned into a migration, so production never got it. Run npm run payload migrate:create, commit the files in src/migrations and deploy, and payload migrate creates the tables before the server starts. On MongoDB this error doesn't happen, since collections are created as documents are written.

Should I use Postgres or MongoDB with Payload?

Payload maintains official adapters for both. Postgres gives you relational tables you can query with SQL and schema changes tracked as migrations. MongoDB stores each document as it looks in Payload and needs no migrations for new fields. Modelence runs both as managed databases, so pick the one your team already knows.

Where does Payload store uploaded media in production?

Wherever the storage adapter for the upload collection sends it. Without one, files go to a folder in the project, which doesn't survive a new container. With @payloadcms/storage-s3 they go to your S3 or R2 bucket, and Payload keeps the file metadata and image sizes in the database and serves files through its API with your access rules applied.

What is PAYLOAD_SECRET used for?

Payload uses it to sign the login tokens of your auth collections, such as users. Set a long random value per environment, for example from openssl rand -hex 32, and keep it stable, because changing it logs everyone out. Set it as a secret in the dashboard rather than committing it.

Is Payload Cloud still available?

Payload's cloud pricing page says deployment of new projects is paused, while existing Cloud projects keep running as normal. New Payload apps are deployed like any Next.js app with a database, on a platform such as Modelence, Railway or Render, or on your own server.

How much does it cost to host Payload on Modelence?

Modelence has a free plan, and an app with managed Postgres or MongoDB needs a paid plan, from $20 a month with $20 of usage included. Your usage is the container's hourly charge for its size plus the database. The blank app used about 235 MB of memory in our test, so Small, with 0.5 vCPU and 1 GB at about $22 a month, is a reasonable start, and your storage provider bills the bucket.

Deploy other stacks

Deploy your Payload app

Start on the free plan and move up when your app needs more.

Or paste this into your coding agent