Deploying NextJS App using cPanel

Jun 25, 2024

Getting Started

Just so you know, you need to have a nextjs application ready to deploy. Because, in this article we’re not going through how to setup nextjs application.

Then, add the following configuration on your next.config file:

const nextConfig = {
  ...
  output: "standalone"
  ...
};

Build Production on Local

Never build a production version on your cPanel. Because, usually shared hosting doesn’t have many resources like VPS or Dedicated Server. Therefore, you should build the production on your local machine.

Run the build script, usually yarn build / npm build / bun run build.

Preparing to Upload

After you run the build script. You will get the output inside .next folder. Next step is, you need to compress the output build into .zip file.

We recommend you create a new folder on your local machine to copy the output build. Here’s all the content you need to copy:

  • Copy .next/standalone into new_folder
  • Copy public into new_folder
  • Copy .next/static into new_folder/.next/static

Your new folder / production folder will look like this:

production folder

Then, you can compress the whole files and folders.

Upload Build Output

Before you upload the output build, you need to create a new folder first on your file manager.

  1. Go to your cPanel
  2. Access File Manager
  3. Create a new folder in the root

cPanel File Manager

  1. Upload your output build on that folder

| *Note: You are only able to deploy nodejs applications to cPanel |hosting that supports nodejs.

JustAHost provides Unlimited Hosting with Rich Features such as NodeJS support, Python support, Ruby support, and many more with Low Costs~!

Setup NodeJS App

  1. Login to your cPanel Account. If you don’t have, you can create one on JustAHost.
  2. Click menu “Setup NodeJS App”
  3. Click “Create Application”

cPanel Setup NodeJS App

Config your nodejs application

NodeJS App Configuration

Things to pay attention to:

1. Node.JS version — Make sure you select the correct nodejs version

2. Application mode — Make sure you choose “Production” mode

3. Application root — Folder location of your app (the folder that you already created in the previous step)

4. Application URL — Make sure you already added the domain on cPanel

5. Applicataion startup file — type “server.js”

You were also able to add some Env Variables if needed.

Then, click “Create”.

Now, your nodejs app should be accessible to the public. Don’t forget to point your domain to your cPanel Hosting.

Back to Top

Follow us on Twitter, Facebook or LinkedIn to receive updates regarding network issues, discounts and more.
2024 © JustAHost. All rights reserved.