DEV Community

Abdulsalam Abdulrahman (Amtech Digital)
Abdulsalam Abdulrahman (Amtech Digital)

Posted on • Edited on

1

Deloy Next or React App to VPS

Step by Step how to deploy next or react application to vps

A. Login to your VPS

 ssh user@hostname
Enter fullscreen mode Exit fullscreen mode

B. Generate SSH public key and add it to your GitHub project

cat ~/.ssh/id_rsa.pub
Enter fullscreen mode Exit fullscreen mode

C. Clone the project to your VPS

clone git@github.com:username/project.git
cd project
Enter fullscreen mode Exit fullscreen mode

D. Install all necessary packages

npm install
npm run build
npm install pm2 --save-dev
npx pm2 start npm --name my-project -- start -- --port=3001
npx pm2 restart my-project
npx pm2 save
Enter fullscreen mode Exit fullscreen mode

Sometime this work's for vite application

npx pm2 start npm --name app-name -- run dev -- --port=3001
npx pm2 save
npx pm2 status
Enter fullscreen mode Exit fullscreen mode

Use this on CD like GitHub action

npx pm2 restart app-name
npx pm2 save
Enter fullscreen mode Exit fullscreen mode

E. Visit the application on the provided port

https://hostname:3001

Enter fullscreen mode Exit fullscreen mode

Congratulations Your Website is live!

Note: There are some necessary adjustments you need to make based on the type of OS and application on the VPS.

@abdulsalamamtech #vps #deploy #next #react

Postmark Image

20% off for developers who'd rather build features than debug email

Stop wrestling with email delivery and get back to the code you love. Postmark handles the complexities of email infrastructure so you can ship your product faster.

Start free

Top comments (0)

Image of Datadog

Get the real story behind DevSecOps

Explore data from thousands of apps to uncover how container image size, deployment frequency, and runtime context affect real-world security. Discover seven key insights that can help you build and ship more secure software.

Read the Report