How to Deploy a Next.js App on cPanel

WhoAmI => notes.sohag.pro/author
Search for a command to run...

WhoAmI => notes.sohag.pro/author
Bhai this thing help me a lot.
A Step-by-Step Guide to AWS VPC Architecture What We're Building Today Imagine being able to build your own digital neighborhood, complete with public areas, private spaces, and secure entrances - all perfectly organized for safety, efficiency, and g...
I had a solid list of reasons my life wasn't moving faster, until a grainy old lecture pointed out the one name missing from it

The finale isn't a victory lap. It's the story of the control I shipped that did nothing, the footgun still sitting in my demo, and the handful of things I'd keep exactly as they are.

How do you hold a large payment for a second pair of eyes without ever letting the unapproved money touch a balance, and how do you stream that decision to the outside world without standing up a broker?

How do you show the total under a parent account when the whole system refuses to store a balance? A recursive query, a trigger that refuses to draw a circle, and a rule about what actually has to sum to zero.

Every time I wanted to change an FX rate I had to edit a file on the server and restart the app. So I moved rates and markup into a live admin API, and then audited it hard enough to find the bug that quietly undid the whole thing.

Hey friend! 👋
You've built your awesome Next.js app and now you're ready to show it off to the world. But… you're on cPanel hosting and not sure what to do next?
No worries—I’ll walk you through everything like we’re sitting side by side. ☕️
This guide is perfect for beginners who are trying to deploy a Next.js app on cPanel the smart way.
Before diving in, make sure you’ve got:
✅ A Next.js app (already created and tested locally)
✅ A cPanel-based hosting account (shared or VPS)
✅ A domain name connected to your cPanel
Optional but helpful: Basic knowledge of how file managers and terminal commands work.
npm vs yarnThese are two different package managers that do the same job: they install and run packages (like Next.js, React, etc.).
npm to create your project, keep using npm.yarn to create your project, stick with yarn.Do NOT use both. Pick the one you started with and use only that throughout the guide.
Most Next.js apps are designed to be run on Vercel or similar platforms. But since we’re on cPanel, we need a custom server using Node.js.
server.js or from the terminal using the below command:touch server.js
Paste this code into server.js:
const { createServer } = require('http')
const { parse } = require('url')
const next = require('next')
const dev = process.env.NODE_ENV !== 'production'
const hostname = 'localhost'
const port = process.env.PORT || 3000
const app = next({ dev, hostname, port })
const handle = app.getRequestHandler()
app.prepare().then(() => {
createServer(async (req, res) => {
try {
const parsedUrl = parse(req.url, true)
await handle(req, res, parsedUrl)
} catch (err) {
console.error('Error occurred handling', req.url, err)
res.statusCode = 500
res.end('internal server error')
}
}).listen(port, (err) => {
if (err) throw err
console.log(`> Ready on http://${hostname}:${port}`)
})
})
This file is like the traffic cop for your app, making sure every request gets routed properly.
package.jsonTell your app how to start in production using the server you just created.
Open your package.json file and change the scripts section like this:
"scripts": {
//... Do not change other commands just the "start" command
"start": "NODE_ENV=production node server.js"
}
This will allow you to run
npm startoryarn startlater, depending on your package manager.
We need to prepare your app for production (i.e., make it fast and optimized).
npm run build
yarn build
This will generate a .next folder containing the production-ready version of your app.
You now need to package your app (without the junk) to upload to cPanel.
node_modules/
.git/
.gitignore
README.md
.zip file.You can name it nextjs-app.zip or anything you like.
Log into your cPanel dashboard
Open the File Manager
Navigate to the directory where your domain lives (usually public_html/)
Upload your .zip file
Once uploaded, right-click the file and select Extract
You should now see all your app files inside the correct folder.
Scroll down to the Software section in cPanel
Click on Setup Node.js App
Click Create Application
Node.js version: Choose the one that matches your development environment (e.g., 22.x)
Application mode: Production
Application root: The folder where your files were extracted (e.g., public_html/nextjs-app)
Application URL: Your domain or subdomain
Application startup file: server.js
Now hit Create—cPanel will set up the environment for your app.
Your app needs packages (like Next.js, React, etc.) to run. Time to install them.
Go to your Node.js App list
Click Stop App (temporarily stop it)
Scroll down and click Run NPM Install
If you used npm when creating the app, this is perfect. If you used yarn, you'll need to install via SSH (next step).
If your hosting allows SSH access:
cd ~/public_html/your-app-folder
Then install packages:
npm install
yarn install
Once complete, go back to cPanel and click Start App again.
Open your browser, type your domain, and hit Enter…
If all went well—you’re now serving your beautiful Next.js app to the world!
Deploying on cPanel might seem scary at first, especially if you're used to platforms like Vercel. But with a little effort, it works beautifully—even on shared hosting.
Created a custom server.js
Built the app
Zipped and uploaded files
Set up Node.js on cPanel
Installed dependencies using either npm or yarn
And finally—ran the app!
Drop them in the comments or reach out to me! I'm happy to help you troubleshoot or celebrate your deployment success 🚀
Happy coding! 🎉💻
This blog is inspired from: