Skip to main content

NextJS Deployment

Port Configuration

Before setting up the port, check available ports with this command:

sudo lsof -i -P -n | grep 8003

Port Occupied

If you see a response like above, it means this port is occupied by another project. Try other ports like 8000, 8001, 8002, etc.

Available Port

If you get no response, it means the port is available and you can use it.

Now add the available port to your package.json and .htaccess files:

Package JSON

Copy the .htaccess file code and change the port number as needed.

Htaccess File

Project Setup

warning

Make sure you have node_modules installed in your directory.

Install project dependencies:

npm install

This will install all the node modules in your directory.

After that, build the production application:

npm run build

Running the PM2 Server

Go to the project root and start the PM2 server:

pm2 start "npm start" -n "YOUR_PROJECT_NAME"

Check if PM2 process is running correctly:

pm2 ls

When you run pm2 ls, you will see one of two types of output:

  1. Error: PM2 Error

  2. Success: PM2 Success

If you're getting errors, run pm2 logs and check the error details.

If successful, set up a startup script to ensure PM2 restarts automatically after a system reboot:

pm2 startup

After setting up PM2 with the startup command, save the current process list

pm2 save

If you want to restart your pm2 process then run pm2 restart id // Replace id with your process id

For example here id is 0 in the above screenshot pm2 restart 0

For deleting the previous project running in the PM2 server, use the following command

pm2 delete "YOUR_PROJECT_NAME"

Your News Web application should now be running with full SEO capabilities.