Contents
Next.js can be deployed in two very different shapes. A static export is a folder of HTML files with no server code, so it runs anywhere. A Node.js deployment keeps a Next server running for server-side rendering (SSR), API routes, middleware and incremental regeneration. Choose first, because the steps differ.
| Feature | Static export | Node.js (SSR) |
|---|---|---|
Static pages, generateStaticParams |
Yes | Yes |
Per-request rendering, cookies(), headers() |
No | Yes |
| API routes / dynamic Route Handlers | No | Yes |
Middleware, ISR / revalidate |
No | Yes |
Built-in next/image optimization |
No | Yes |
| Plan needed | Any plan | AI/Developer plan |
Prerequisites
- Node.js 20 or 24 on your computer. Next.js 16 needs Node 20.9 or newer.
- A project that builds locally with
npm run build. - A domain pointing to your hosting account.
- For SSR: a plan with Setup Node.js App and SSH.
Route 1: static export (any plan)
1. Configure next.config.mjs
/** @type {import('next').NextConfig} */
const nextConfig = {
output: "export",
trailingSlash: true,
images: { unoptimized: true },
};
export default nextConfig;
trailingSlash: true writes about/index.html instead of about.html, so /about/ opens without rewrite rules. images.unoptimized is required because there is no server to resize images.
2. Build
npm ci
npm run build
The result is in the out/ folder. Since Next.js 14 there is no separate next export command.
3. Upload
Compress the contents of out/ (not the folder itself) into a ZIP. In cPanel open Files › File Manager, go to public_html, click Upload, then right-click the ZIP and choose Extract. Add an .htaccess file so missing pages show your Next 404 page:
ErrorDocument 404 /404.html
Route 2: SSR with Setup Node.js App (AI/Developer plans)
1. Add a server.js
Passenger needs a JavaScript startup file, not a CLI command, so add this file to the project root. It does what next start does:
const { createServer } = require("http");
const next = require("next");
const port = process.env.PORT || 3000;
const app = next({ dev: false, dir: __dirname });
const handle = app.getRequestHandler();
app.prepare().then(() => {
createServer((req, res) => handle(req, res)).listen(port, () => {
console.log(`Next.js ready on port ${port}`);
});
});
If your package.json has "type": "module", name it server.cjs. Prefer next.config.mjs over next.config.ts on the server so the config loads without TypeScript tooling.
2. Build where you have memory
Build on your computer or in GitHub Actions:
npm ci
npm run build
Upload everything except node_modules and .next/cache: the .next folder, public, package.json, package-lock.json, next.config.mjs and server.js. Building on the server is possible for small sites, but larger builds can stop with Killed or JavaScript heap out of memory under your account’s limits.
3. Create the Node.js app
Open Software › Setup Node.js App › Create Application:
- Node.js version: 20 or 24
- Application mode: Production (sets
NODE_ENV=production) - Application root:
nextapp - Application URL: your domain
- Application startup file:
server.js - Passenger log file:
/home/USER/logs/nextapp.log
Click Create. Under Environment variables add your server-side settings. Variables starting with NEXT_PUBLIC_ are baked in at build time, so they must exist where you build, not only here.
4. Install dependencies
Click Run NPM Install, or over SSH:
source /home/USER/nodevenv/nextapp/20/bin/activate && cd /home/USER/nextapp
npm install
5. Restart after every deploy
Click Restart in Setup Node.js App, or run touch /home/USER/nextapp/tmp/restart.txt.
Troubleshooting
- Direct links or refresh give 404 on the static export: set
trailingSlash: trueand rebuild, and keep theErrorDocumentline. Page "/blog/[slug]" is missing "generateStaticParams()": every dynamic route needsgenerateStaticParamsin an export, or you need the SSR route.Could not find a production build in the '.next' directory: the.nextfolder wasn’t uploaded to the app root, or the build failed.- The selector complains about node_modules: delete the
node_modulesfolder you uploaded and click Run NPM Install again. - An error page instead of the site: read the Passenger log file you set when creating the app; see Passenger app error. Don’t hard-code a port; Passenger provides it.
On ArabyHost
A static export runs on every plan, including shared hosting: LiteSpeed serves the files and AutoSSL issues the certificate automatically. SSR runs on the AI/Developer plans, which include Node.js 20 and 24 through the CloudLinux selector (Phusion Passenger), SSH jailed in CageFS and Git, so you can deploy from GitHub with .cpanel.yml or from GitHub Actions over SSH. Server-side features such as ISR and image optimization use your account’s own resource limits; there is no root access and no Docker. If you only have a client-side app, see deploying a React app, and for general Node apps deploying Node.js.
FAQ
Can I host Next.js on shared hosting?
Yes, as a static export: the build is plain HTML, CSS and JavaScript that any plan serves. Server-side rendering, API routes and middleware need a Node.js process, which on ArabyHost means the AI/Developer plans.
Why build locally instead of on the server?
`next build` needs a lot of memory and CPU for a short time, and on shared hosting your account has fixed resource limits that can stop it. Building on your machine or in GitHub Actions and uploading the result avoids that.
Should I upload node_modules?
No. Setup Node.js App keeps node_modules in a separate virtual environment and links it into your app; a real node_modules folder in the app root makes the selector refuse to work. Click Run NPM Install instead.