Raddy Website Design & Development Tutorials | RaddyDev

Next.js 14 Deployment to VPS with GitHub Actions CI/CD

By Raddy in NextJs ·

Learn how to streamline your web development workflow by deploying Next.js 14 to a Virtual Private Server (VPS) effortlessly with the power of GitHub Actions Continuous Integration/Continuous Deployment (CI/CD).

Go to NodeJs Yml File.

My Notes:

1) Create A NextJS 14 App

Create NextJs Website

Now that you have a fully working website, we need to publish it on Github.

2) Create GitHub Repository

It can be public or private.

3) Create Digital Ocean Droplet – VPS

Ubuntu System Requirements

The recommended minimum system requirements are:

  • CPU: 1 gigahertz or better
  • RAM: 1 gigabyte or more
  • Disk: a minimum of 2.5 gigabytes

Source: https://ubuntu.com/server/docs/installation

4) Create SSH Keys

SSH keys have password authentication disabled by default. This makes them secure against brute-force attacks.

  • Create a folder to store the SSH Keys
  • Create Keys – Created on Droplet Create (follow instructions)
  • add Pub Key to Droplet on creation

Setup Reserved IP

(A DigitalOcean Reserved IP address is a publicly-accessible static IP address that you can assign to a Droplet and then reassign to another Droplet later, as needed.)

SSH to Server

To connect to your server you can use your the ipv4 or Reserved IP from your dashboard.

SSH

Download and install updates for outdated packages and dependency’s on the system.

Update apt
Upgrade apt

Create a New User

Add user
Set user password
Add user to a "sudo" group

usermod: This is the command itself, which is used to modify user accounts.

-aG: These are options/flags that modify the behavior of the usermod command:

  • -a: This option stands for “append” and is used to add the user to the specified groups without removing them from any existing groups.
  • -G: This option is followed by a list of groups to which you want to add the user.
Check username path
Switch to new user

5) Create Github Workflow

SSH to server and run the instructions from Github.

Install Packages

Switch User from Root to Rad

Install NodeJs – Go to Option 3:

https://www.digitalocean.com/community/tutorials/how-to-install-node-js-on-ubuntu-20-04

Install NPM
Install PM2
Start a Process
Setup Github Action Runner
<code>pm2 startup</code> on restart
Test by Shutting down server

6) Reverse Proxy

Use the following Digital Ocean Guide up to

Restart Nginx

7) Point Domain name A records

  • A record to IP
  • A record with www to IP

8) SSL

To setup the SSL follow: How to secure Nginx with let’s encrypt on ubuntu 20-04

Nice to know: How to setup a firewall with ufw on ubuntu and debian clud server

9) Extra

If you want to redirect www.my-website.com to my-website.com, remove www.my-website.com from the server_name line, and save and exit the file.

/etc/nginx/conf.d/my-website.com.conf
Restart

Firewall

Make sure that your firewall allows HTTPS traffic.

UFW
traffic

If your ufw is disabled:

ufw

Setup basic Firewall

ufw

Last thing, make sure that you have port 443 open.

Other useful commands

Permission Error Fix
Good to know

That’s all.

Node.js.yml + Dot.env Example and Reload

node.js.yml

Leave a Reply

Your email address will not be published. Required fields are marked *

Buy Me A Coffee