Skip to main content

Next.js Deployment

This guide explains how to deploy your eBroker web application with SEO support using Next.js on a VPS server.

warning

This is an advanced deployment option for users who have a VPS server and are familiar with Node.js, npm, and pm2. The instructions assume you're using a Debian-based Linux distribution.

Uploading Your Project​

Before starting deployment, upload your project to the server:

  1. Use an FTP client like FileZilla to upload your project files to your server
  2. Alternatively, use Git to clone your repository directly on the server

Installing Node.js​

Node.js can be installed using NVM (Node Version Manager) to easily manage multiple Node.js versions:

sudo apt install curl
curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash
source ~/.bashrc # or restart your terminal
nvm install 22

Verify the installation with:

node -v

For more information, refer to the official Node.js documentation.

Installing PM2​

PM2 is a production process manager for Node.js applications. Install it globally with:

npm install pm2 -g

Setting Up the Project​

Make sure you have all the dependencies installed:

npm install

Build the production application:

npm run build

Running with PM2​

Start your application with PM2:

pm2 start "npm start" -n "YOUR_PROJECT_NAME"

Check if the PM2 process is running correctly:

pm2 ls

You should see your application in the list of running processes:

PM2 Success

If you see errors:

PM2 Error

Run pm2 logs to see detailed error messages.

Managing PM2 Processes​

To restart a PM2 process:

pm2 restart [id]

Replace [id] with your process ID (e.g., pm2 restart 0).

To delete a PM2 process:

pm2 delete "YOUR_PROJECT_NAME"

For more information, refer to the official PM2 documentation.

Auto-Start on Server Reboot​

To ensure your application automatically restarts when the hosting server reboots, you need to save the current PM2 process list and configure PM2 to launch on system startup.

Step 1 — Save the current PM2 process list:

pm2 save

This saves all currently running processes so PM2 can restore them after a reboot.

Step 2 — Generate and configure the startup script:

pm2 startup

Testing Your Deployment​

After completing all steps:

  1. Visit your website using your domain name
  2. Verify that all pages load correctly with proper SEO metadata
  3. Check that server-side rendering is working by viewing the page source
  4. Test all functionality to ensure everything works as expected