SSH into your Ubuntu server
ssh username@your_server_ip
Update packages
sudo apt update
sudo apt upgrade -y
Install Node.js, Nginx, Git, and PM2
sudo apt install nginx git -y
Install Node.js. Recommended: use NodeSource or nvm. Example with nvm
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
source ~/.bashrc
nvm install --lts
nvm use --lts
Check versions
node -v
npm -v
Install PM2 globally
npm install -g pm2
Upload or clone your Next.js project
cd /var/www
sudo git clone https://github.com/your-username/your-next-app.git
sudo chown -R $USER:$USER /var/www/your-next-app
cd /var/www/your-next-app
Install dependencies
npm install
Build the Next.js app
npm run build
Run Next.js with PM2
pm2 start npm --name "next-app" -- start
Check status
pm2 status
