Skip to main content
Next.js doesn’t ship with a Passenger-compatible startup by default. The fix: a custom server that exports a Node http handler. For the underlying tool, see Node.js.

Before you begin

  • A Node.js app already created in cPanel, version 20 or 22.
  • The app root contains your Next project (package.json, pages/ or app/, next.config.js).
  • SSH access (recommended for builds).

Build for production

Builds can OOM under the cPanel UI on a 1 GB plan. Build over SSH:
source ~/nodevenv/myapp/22/bin/activate && cd ~/myapp
npm install
npm run build
Check next is in dependencies, not devDependencies.

Add a Passenger-compatible server

1

Create server.js in the app root

server.js
const http = require('http');
const next = require('next');

const app = next({ dev: false });
const handle = app.getRequestHandler();

module.exports = (async () => {
  await app.prepare();
  return http.createServer((req, res) => handle(req, res));
})();
2

Set the startup file

In cPanel, Setup Node.js AppEditApplication startup file: server.js. Save.
3

Restart

Click Restart, or touch ~/myapp/tmp/restart.txt.

Common issues

Move next from devDependencies into dependencies and re-run npm install.
Build on a dev machine instead, then rsync .next/ and public/ up. Skip building on the server entirely.
The custom server above hands every request to Next. If you wrap routes in custom Express middleware, make sure the catch-all delegates back to handle(req, res).

Need a hand?

Open a ticket

Best for anything that needs an account check or a config change on our end.

Live chat

Faster for quick questions during business hours.