Jul 30, 2025 / 88 views / 5 minutes read
In this article, I'll walk you through how to deploy NEXT.js projects on a VPS using PM2.
For this article, you'll need a successfully built NEXT.js project that's ready to deploy. You'll also need a VPS server, which I've covered how to configure in How to Configure and Secure Your New Linux VPS article. Once you have those, you're good to go.
If you have a project developed within the NPM ecosystem and want to make it available on the internet using a VPS, you'll need a process management tool. This tool will help you manage and monitor the availability of your project (app). PM2 is an excellent choice for this.
To install PM2, you first need to have Node.js installed on your VPS. Then, you can run this command to install PM2 globally:
npm I pm2 -g
After the installation is complete, to ensure everything is set up as expected, you can run the command below. If you see the PM2 version in the output, everything is correctly configured:
pm2 –version
Next, to add your project to PM2, you'll need to choose a name and a port that your reverse proxy (like NGINX) will refer to. Then, you can run this command:
Note: By default, PM2 defines your project with a "fork" status, meaning it runs on a single thread. If your project requires heavy processing and needs to utilize the maximum CPU cores or more than what the "fork" status offers, you'll need to specify this in the add project command. You can read more about this in the official documentation.
If your terminal is currently in your project directory, run this:
pm2 start npm –name <name> -- run start -- -p <port>
Otherwise, run this and specify the project path:
pm2 start npm –name <name> --cwd /path/to/your/project – run start -- -p <port>
After running this command, you'll see a table as output displaying your project, which has been added. If there are no errors during the start process, you'll see "online" status in green.
Next, you need to save the changes by running this:
pm2 save
By default, PM2 won't start on system startup. If your VPS shuts down and restarts for any reason, you'll need to run PM2 again. To ensure it starts automatically, you'll need to run this:
pm2 startup
After running this, you'll see output text suggesting you run a command:
[PM2] To setup the Startup Script, copy/paste the following command: sudo env PATH=$PATH:/usr/bin /usr/lib/node_modules/pm2/bin/pm2 startup systemd -u ubuntu --hp /home/ubuntu
Copy the command after "command:" and run it. After that, you're all set.
You can view your project list by running:
pm2 [list | ls | status]
In the output, you'll see a table with 7 columns:
To see more details, you can also run the command below:
pm2 monit
In this article, I aimed to show you how to deploy a NEXT.js project on a VPS using PM2, which is a simple tool with an easier learning curve.