Skip to main content

Site Build and Deploy

Deploy in Your Own Server

Next.js can be deployed to any VPS (Virtual Private Server) hosting provider that supports Node.js.

If you’ve followed the instructions so far, your package.json should have the following build and start scripts:

/src/language?/i18n.js
{
"scripts": {
"dev": "next",
"build": "next build",
"start": "next start"
}
}

Package Installation

To install node_module , run the following command

yarn
Mandatory

Make sure you have node_modules installed in your directory.

The above command will install all the node modules in your directory.

Project Build

In your own terminal, run the following command, which will build the production application in the .next folder.

yarn run build

Project Run

  • Install PM2 in your server

    npm install pm2 -g
  • To run the site in your server, you have to run the PM2 command given below-

    pm2 start npm --name "`YOUR_PROJECT_NAME`" -- start
  • To re-deploy your site after some changes, you must run the following commands

    pm2 delete "YOUR_PROJECT_NAME"
    pm2 start npm --name "YOUR_PROJECT_NAME" -- start
MANDATORY

Must follow the above instructions

info

For more information, use official documentation

For Local Build and Deploy

For local build -

  • You have to run the following command on your project directory.

    yarn run build
  • After the successful build, make sure your directory has the .next folder then deploy the whole project contained with .next to the server.

tip

Recommended tutorial is below 👇

Deploy to Vercel

The easiest way to deploy Next.js to production is to use the Vercel platform, developed by the creators of Next.js.

Vercel is a serverless platform for static and hybrid applications built to integrate with your headless content, commerce, or database. We make it easier for frontend teams to develop, preview, and ship delightful user experiences, where performance is the default. You can start using it for free — no credit card required.

Create a Vercel Account

First, go to versel official site to create a vercel account. Follow the instruction and complete the sign-up process.

tip

Recommended documentation link is below 👇

https://nextjs.org/learn/basics/deploying-nextjs-app/deploy