Back to Browse

Deploy Like a Pro — Next.js 16 CI/CD on a VPS (Hostinger + PM2 + GitHub Actions)

725 views
Nov 21, 2025
1:02:40

Deploy your Next.js application automatically using a full CI/CD pipeline powered by GitHub Actions. In this tutorial, we set up a Hostinger VPS, configure SSH deploy keys, install PM2, and build a complete automated deployment workflow that runs every time you push to GitHub. This guide works for any VPS provider (Hostinger, DigitalOcean, Linode, Vultr, AWS EC2, etc.) and supports all modern Next.js versions, including Next.js 16 with Turbopack. By the end of this video, your VPS will automatically pull your latest code, install dependencies, rebuild your Next.js app, and restart your PM2 server with zero manual work. Based on the portfolio project: https://www.youtube.com/watch?v=H_6EdHkLVSY&t=2s Github repo: https://github.com/Akintola97/portfolio-yt.git Deploying Next.js application to Hostinger video: https://www.youtube.com/watch?v=XDS2UzWBlEE&t=172s TIMESTAMPS 00:00 – Introduction 05:01 – Deploying the app on Hostinger 12:40 – Configuring CI/CD pipeline with GitHub Actions 1:02:35 – Outro **10 Steps to Set Up CI/CD for Next.js on a VPS (GitHub Actions + PM2 + Nginx)** 1. **SSH into your VPS and install Node + PM2** Make sure your VPS has Node.js (v20+) and PM2 installed to run your Next.js production app. 2. **Clone your project onto the VPS** Use `git clone` to place your app inside the directory where you’ll serve it (e.g., `/root/myapp/app-folder`). 3. **Start the app manually with PM2** Run `npm run build` and then start the app using: `pm2 start npm --name "your-app-name" -- start`. 4. **Configure Nginx to proxy your app** Point your domain to your VPS and use Nginx to reverse-proxy to your PM2 port. 5. **Generate an SSH deploy key on your VPS** Run: `ssh-keygen -t ed25519 -C "github-deploy"` Copy the public key (`.pub`) and add it as a Deploy Key on GitHub. 6. **Add the private key to GitHub Secrets** Add the full contents of your private key as `VPS_SSH_KEY` in: GitHub → Settings → Secrets → Actions. 7. **Add your required secrets (env vars)** Combine ALL your `.env` values into one multi-line secret called `APP_ENV` (or separate secrets if you prefer). 8. **Set the correct VPS app directory path** SSH into your VPS → `cd` into your project folder → run `pwd` → copy this exact path into a GitHub secret called `VPS_APP_DIR`. 9. **Create your GitHub Actions workflow file** Inside your repo, create: `.github/workflows/deploy.yml` This file installs Node, builds your app, rsyncs files to your VPS, writes your `.env`, installs deps, rebuilds on the server, and restarts PM2. 10. **Push to main to trigger automatic deployment** Every push to the `main` branch will now automatically: * build your app * upload changes to your VPS * rewrite the `.env` file * rebuild on the VPS * restart PM2 * update your live production site

Download

0 formats

No download links available.

Deploy Like a Pro — Next.js 16 CI/CD on a VPS (Hostinger + PM2 + GitHub Actions) | NatokHD