Next.js hosting and how to deploy Next.js step by step

Next.js hosting and how to deploy Next.js

Next.js is not a static site you can copy to a cPanel account. Most Next.js apps need a Node.js process running continuously to render pages and answer API routes. So the first question to ask of any Next.js hosting is whether it can run Node.js long term.

What Next.js needs from a host

  • The right Node.js version. Declare it in package.json so your machine and the server agree:
{ "engines": { "node": ">=20" } }
  • Enough RAM to build. next build uses more memory than running the app. Large projects can hit JavaScript heap out of memory on very small plans.
  • Automatic builds and restarts, so updates do not mean logging in to a server.
  • HTTPS and a reverse proxy in front of the app.

Projects using output: "export" produce a static site in out, which any host can serve, but they lose server features such as API routes and server rendering.

Prepare your project

Test exactly what the server will run:

npm ci
npm run build
npm start

Check that package.json has all three scripts:

{
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start"
  }
}

Then deal with environment variables, the most common source of Next.js problems on a server:

  • NEXT_PUBLIC_ variables are embedded in the code at build time. Changing one means rebuilding, and anyone can read it in the browser, so never put secrets there.
  • Variables without the prefix are server-only. API keys and database passwords belong here.
  • Add an .env.example listing the names, without real values.

If you use next-auth, set the URL variable to your real address, or sign-in will redirect to localhost.

Deploy Next.js on VibeVN

  1. Push your code to GitHub.
  2. Open a new deployment and choose the repository and branch. Next.js is detected from package.json, with port 3000.
  3. Fill in the environment variables read from .env.example.
  4. Choose CPU, RAM and a subdomain, then deploy.
  5. Follow the logs. When the health check passes, the site has an HTTPS address.

After that, each git push to the chosen branch redeploys the site. If your code uses Prisma with PostgreSQL or MySQL, the database is detected from schema.prisma and created for the site. The full process is in how to deploy a vibe coded website.

Things to watch when self-hosting Next.js

Uploaded files. A container's disk is temporary and is replaced on each deployment. On VibeVN, /app/data persists, so user uploads must go there or to external storage.

next/image optimization. It runs on your server and uses CPU when there are many images. On small plans, prepare images at the right size and prefer WebP.

Calling your own API during the build. A static page that fetches http://localhost:3000/api/... while building fails with ECONNREFUSED, because the server is not running yet. Call the data function directly instead.

Databases during the build. Similarly, a page that queries the database at build time fails if the database is not ready. Mark it as dynamic if the data changes often.

How much RAM do you need?

There is no universal number, since it depends on your pages and libraries. Start with a modest plan, see whether the build passes and how much memory the app uses, and upgrade if needed. exit code 137 or OOMKilled means it ran out of memory. Compare options on the pricing page.

Hitting errors?

Fixing Next.js build errors lists the common failures by group, with fixes.

Frequently asked questions

Does Next.js run on shared hosting?

Usually not, unless the plan supports Node.js applications and lets you build. If you only need a static site, use output: "export".

Do I have to use Vercel?

No. Vercel created Next.js and integrates with it closely, but Next.js is open source and runs on any server with Node.js. Some platform-specific optimizations may need extra setup when you run it yourself.