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:
"build": "next build",
"start": "next start"
node_module , run the following command
Make sure you have
node_modules installed in your directory.
The above command will install all the node modules in your directory.
In your own terminal, run the following command, which will build the production application in the .next folder.
yarn run build
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
Must follow the above instructions
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.
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.
Recommended documentation link is below 👇