DEV Community

Cover image for How to Deploy a Next.js App on cPanel Shared Hosting (Beginner-Friendly Guide)
Waseem Akram
Waseem Akram

Posted on

How to Deploy a Next.js App on cPanel Shared Hosting (Beginner-Friendly Guide)

If you have a shared hosting account with cPanel and want to run a Next.js website on your own domain, this guide will help you do it step by step.

I created this guide for beginners, so even if you have never deployed a Next.js project before, you should be able to follow along.

===========Quick Summary (For Experienced Developers)============

If you're already familiar with Next.js and cPanel, here's the short version:

✅ Build the project on your local computer npm run build

✅ Remove unnecessary files before uploading node_modules, .git, .next/cache

✅ Create a Node.js Application in cPanel

✅ Upload your project files

✅ Run: npm install

✅ Configure startup file (app.js or server.js)

✅ Restart the Node.js application

✅ Open your domain and test

If you need detailed instructions, continue reading below.

=================================================================

Why Deploy Next.js on Shared Hosting?

Many developers use platforms like Vercel for Next.js hosting. However, some clients already have shared hosting and don't want to purchase a VPS or additional hosting.

If your hosting provider supports Node.js in cPanel, you can run a Next.js application directly from your hosting account.

Note: Shared hosting is usually slower than VPS or cloud hosting. It works best for small projects, personal websites, staging environments, or low-traffic applications.

Requirements

Before starting, make sure you have:

  • A Next.js project
  • cPanel access
  • Node.js Application feature enabled
  • A domain or subdomain connected to your hosting account

=================================================================

Let's Setup Nodejs App in cPanel 😎

Step 1: Build Your Next.js Project Locally

Do not build the project on shared hosting. Build it locally and then upload it to cPanel.

Open your terminal and run: npm run build

This creates an optimized production build.


Step 2: Clean the Project Before Uploading

Uploading unnecessary files makes deployment slower.

You can safely remove:

node_modules 
.git 
.next/cache
Enter fullscreen mode Exit fullscreen mode

Keep these folders:

.next 
public 
src 
app 
pages 
package.json
Enter fullscreen mode Exit fullscreen mode

This reduces upload size significantly.


Step 3: Create a Node.js Application in cPanel

Login to cPanel.

Navigate to: Software -> Setup Node.js App

Click: Create Application

Choose:

  • Node.js version (latest available)
  • Domain or subdomain
  • Application root directory

Save the application.

After creating the Node.js app, open the app URL. If everything is set up correctly, you will see a message confirming that the app was created successfully.

It works!

NodeJS 22.8.0
Enter fullscreen mode Exit fullscreen mode

Inside your site folder (app directory), you should also find important files like .htaccess and app.js.

All other extra folders are not required for our Next.js app and can be safely removed to keep the project clean and simple.


Step 4: Upload Your Project Files

Open: cPanel → File Manager

Upload your project as a ZIP file.

After uploading:

  1. Extract the ZIP.
  2. Move files into the application root directory.
  3. Verify that package.json is visible.

Your structure should look similar to:

my-app/ 
  ├── .next/ 
  ├── public/ 
  ├── package.json 
  ├── app.js`
Enter fullscreen mode Exit fullscreen mode


Step 5: Install Dependencies

Return to the Node.js Application page.

Install project dependencies: npm install

Wait until installation completes.

Do NOT run: npm run dev

The development server should never be used in production.

Step 6: Configure the Startup File

Your hosting provider may require a startup file such as:

app.js or server.js

This file starts the Next.js application and handles incoming requests.

If your hosting provider automatically creates an app.js file, update it according to your hosting requirements.


Step 7: Restart the Application

After uploading files and installing dependencies:

  • Stop the application
  • Start it again

or click: Restart inside cPanel.


Step 8: Test Your Website

Open your domain in a browser.

If everything is configured correctly, your Next.js application should load successfully.

Example: https://yourdomain.com

========================= ## Common Problems ====================

  1. Website Shows 500 Error

Check:

  • package.json exists
  • dependencies installed
  • startup file path is correct
  1. Build Not Found Error

Make sure you ran: npm run build

before uploading.

The .next folder must be uploaded.

  1. Node.js Option Missing in cPanel

Some shared hosting plans do not support Node.js.

Contact your hosting provider and ask whether Node.js Applications are available.

Final Thoughts

Deploying Next.js on cPanel is possible when your hosting provider supports Node.js. While shared hosting is not the ideal environment for large Next.js applications, it works well for testing, personal projects, small business websites, and staging environments.

If your project starts receiving significant traffic, consider moving to a VPS Hosting or a platform designed specifically for Next.js App hosting.

Happy Deploying!

Top comments (0)