cPanel

Deploy a Next.js app on cPanel hosting with Setup Node.js App

Run a server-rendered Next.js site on MdmHost cPanel hosting: build it, upload it, create the app in Setup Node.js App with a custom server file and restart.

IntermediatecPanel hosting2 min read

MdmHost cPanel hosting runs CloudLinux, so you can host a full Next.js app (server rendering, API routes, middleware) with the Setup Node.js App tool. Passenger starts the app and connects it to your domain, so no ports or proxies are needed. This guide is for Next.js specifically; for the general app screen see Set up a Node.js app in cPanel.

Before you start

  • A cPanel hosting account with Setup Node.js App under Software.
  • Your Next.js project working locally with npm run build and npm start.
  • Node.js on your computer at the same major version you will pick in cPanel.
  • Optional but useful: SSH access (cPanel SSH access).

Tip: If your site has no server features, a static export is simpler and faster on cPanel. See Next.js static export.

Add a server.js entry file

Passenger needs a JavaScript file to start, not an npm script. Create server.js in the project root:

const { createServer } = require('http');
const next = require('next');

const port = process.env.PORT || 3000;
const app = next({ dev: false });
const handle = app.getRequestHandler();

app.prepare().then(() => {
  createServer((req, res) => handle(req, res)).listen(port);
});

Build the app

Building on shared hosting can hit memory limits, so build on your computer:

npm ci
npm run build

Upload everything except node_modules and .git: the .next folder, public, package.json, package-lock.json, next.config.js and server.js. Zip the files, upload with cPanel → Files → File Manager to a folder such as /home/USER/nextapp (outside public_html) and extract.

Create the Node.js app

  1. Open cPanel → Software → Setup Node.js App and click Create Application.
  2. Node.js version: the same major version you built with.
  3. Application mode: Production.
  4. Application root: nextapp.
  5. Application URL: your domain (leave the path empty for the whole site).
  6. Application startup file: server.js.
  7. Add environment variables such as NODE_ENV=production, then click Create.

Install dependencies and start

  1. On the app screen click Run NPM Install. CloudLinux places node_modules in a virtual environment and links it into your app folder.
  2. Click Restart and open your domain.

Using SSH instead? Copy the source command shown at the top of the app screen, run it, then npm install --omit=dev.

Deploy updates

  1. Build locally again and upload the new .next folder (and any changed files).
  2. If package.json changed, click Run NPM Install.
  3. Click Restart. From SSH you can instead run touch tmp/restart.txt in the app root.

Troubleshooting

  • 503 Service Unavailable — the app crashed at start. Check stderr.log in the app root and see CloudLinux Node.js app troubleshooting.
  • Could not find a production build — the .next folder was not uploaded or was built with next dev.
  • Folder named node_modules already exists — delete your uploaded node_modules; CloudLinux manages it.

Next steps

Need a plan? See MdmHost web hosting.

Was this guide helpful?

Still stuck?

Ask MdmHost AI for a quick answer, or open a ticket and our team will take a look. We are here 24/7.