MENU

Ideas
Contact Me
Blogs
YouTube
Portfolio

© 2024 Saviourdev. All rights reserved.

28 Apr 20267 min read21 views

Stop Overpaying for Hosting — Deploy Your Next.js App on cPanel for Next to Nothing

A no-nonsense, step-by-step walkthrough to get your Next.js 15/16 project running on cheap shared/cloud cPanel hosting — without needing Vercel, Railway, or any expensive platform.

Adarsh VermaPublished under /stop-overpaying-for-hosting-deploy-your-nextjs-app-on-cpanel-for-next-to-nothing

Topics

Next.js hosting on cPaneldeploy Next.js on cPanelcheap Next.js hostingaffordable Next.js deploymentNext.js production deploymentshared hosting Next.jsNode.js hosting cPanel
Next.js cPanel Hosting Node.js Deployment Budget Hosting

Deploying a Next.js app doesn't always mean shelling out for Vercel's Pro plan or a costly VPS. If you already have cPanel-based shared or cloud hosting, you can serve a full Next.js application — server-side rendering and all — with zero extra infrastructure cost. This guide walks you through every step: from zipping your project correctly to running pnpm build inside the terminal and restarting your Node.js app.

Who is this for? Developers who have cPanel hosting (most budget shared/cloud hosts offer it) and want to deploy a Next.js project without switching to a more expensive platform.

Step 1 — Create a Clean Archive of Your Project

Before uploading anything, you need to create a ZIP archive of your project — but carefully excluding heavy and environment-specific folders that should not be uploaded.

Exclude the following from your ZIP:

  • node_modules/ — these will be reinstalled on the server
  • .next/ — the build output will be generated on the server
  • .git/ — version control data is not needed
  • Any other dot files like .env.local if you plan to set env vars via cPanel (recommended)
Warning: Uploading node_modules is a common mistake. It can contain tens of thousands of files and will cause upload timeouts, extraction errors, and permission issues on shared hosts.

On most systems you can right-click and compress, or via terminal:

# From your project root zip -r my-next-app.zip . \ --exclude "node_modules/*" \ --exclude ".next/*" \ --exclude ".git/*"

Step 2 — Set Up Node.js App in cPanel

Log into cPanel and locate the Setup Node.js App section (usually under the Software category). Click Create Application and fill in the following:

  • 1 Node.js version — Match this exactly to the version defined in your package.json under engines.node, or whatever version you developed with locally. Mismatched versions cause subtle runtime failures.
  • 2 Application mode — Set to PRODUCTION for live sites. Use DEVELOPMENT only for testing (it enables verbose error pages).
  • 3 Application root — The folder path where your project lives (e.g. my-next-app/).
  • 4 Application URL — The domain or subdomain to serve the app on.
  • 5 Application startup file — Set this to server.js (or app.js — whichever you create in the next step).
Node version tip: Open your project's package.json and check the engines field, or run node -v locally to confirm your development version.

Step 3 — Add Environment Variables

Still inside the Node.js app setup, scroll down to the Environment Variables section and add:

NODE_ENV = production

You can also add any other environment variables your app needs here (database URLs, API keys, etc.) instead of keeping them in a .env file. This is the more secure and recommended approach on shared hosting.


Step 4 — Create Your Custom Startup File

Next.js on cPanel doesn't use next start directly — you need a custom Node.js HTTP server that boots Next and handles requests. Create a file called server.js (or app.js) in the root of your project with the following code:

const { createServer } = require('http'); const { parse } = require('url'); const next = require('next'); // Set dev: false for production build const dev = false; const app = next({ dev }); const handle = app.getRequestHandler(); // cPanel assigns a PORT via env — fallback to 3005 for local testing const port = process.env.PORT || 3005; app.prepare().then(() => { createServer((req, res) => { const parsedUrl = parse(req.url, true); handle(req, res, parsedUrl); }).listen(port, (err) => { if (err) throw err; console.log(`> Server running on http://localhost:${port}`); }); });
Why dev: false? Setting dev: false tells Next.js to serve the pre-built .next/ output instead of compiling on the fly. This is required for production — without it Next.js will try to JIT-compile your pages and likely crash on limited-memory shared hosting.

Step 5 — Upload Your ZIP and Extract It

Go to cPanel's File Manager and navigate to the application root folder you configured in Step 2. Upload your ZIP file there, then right-click it and select Extract. Make sure all files land directly in the app root — not nested inside an extra subfolder.

Double-check: After extraction, your app root should contain package.json, server.js, pages/ (or app/), and other source files — but no node_modules or .next yet.

Step 6 — Copy the Virtual Environment Path

Back in Setup Node.js App, find your app entry and look for the virtual environment path — it looks something like:

/home/yourusername/nodevenv/my-next-app/18/bin/activate

Copy this path. You'll need it in the terminal to activate the correct Node.js environment before running any commands.


Step 7 — Open cPanel Terminal and Install Dependencies

Find Terminal in cPanel (under Advanced). Once inside, activate the virtual environment, then navigate to your project:

# Activate the Node.js virtual environment (paste your copied path) source /home/yourusername/nodevenv/my-next-app/18/bin/activate # Navigate to your app folder cd ~/my-next-app

Now install pnpm globally using npm:

npm install -g pnpm

Then clean up any accidental leftover folders, just to be safe:

rm -rf node_modules rm -rf .next

Install your project dependencies:

pnpm install
Why pnpm? pnpm uses a content-addressable store and hard links — it installs significantly faster than npm and uses less disk space, which matters on shared hosting with disk quotas.

Step 8 — Build Your Next.js App

With dependencies installed, run the production build. This generates the optimized .next/ folder that your server will serve.

pnpm build

The build process will compile pages, optimize images, generate static assets, and output everything into .next/. This can take anywhere from 30 seconds to a few minutes depending on project size and server resources.

Build failing? Common causes: missing environment variables (add them in cPanel's env section), TypeScript errors, or Node.js version mismatch. Check the terminal output carefully — Next.js gives detailed error messages.

Step 9 — Restart the Node.js App

After a successful build, go back to Setup Node.js App in cPanel and click Restart on your application. This tells cPanel's passenger process manager to pick up the new build and start serving your app.

Wait a few seconds after restarting before visiting your URL — cPanel's Passenger takes a moment to boot the Node.js process and load Next.js.
Every future deployment follows the same flow: re-upload a fresh ZIP → extract → pnpm installpnpm build → Restart app. If only code changed and no new packages were added, you can skip pnpm install.

Quick Reference — Full Command Sequence

# 1. Activate virtual environment source /home/yourusername/nodevenv/my-next-app/18/bin/activate # 2. Navigate to app cd ~/my-next-app # 3. Install pnpm globally npm install -g pnpm # 4. Clean up old artifacts rm -rf node_modules .next # 5. Install dependencies pnpm install # 6. Build for production pnpm build # 7. Go to cPanel → Setup Node.js App → Restart

That's it — your Next.js 16 app is live on budget cPanel cloud hosting, no Vercel required. The same workflow works for any Next.js version 13 and above using the App Router or Pages Router.

Discussion

Comments

0 comments

Sign in with Google to join the discussion.

Loading comments...

Stay Connected

Follow and Explore More

Watch more on YouTube, explore the rest of the brand, and jump back to the homepage to discover ideas, projects, and more.