Self host Next.js website on an Ubuntu server with Auto Deploy on commits!
To host Next.js app/website you only need a server running Node.js. In this video you will learn how to host a next.js website or app on an ubuntu (linux) server in the cloud which you can get from Digital ocean or AWS. As a note, In this example we are not using Vercel, Netlify or any of the app hosting platforms on digital ocean or aws as those are also abstractions. We are setting up a clean instant ubuntu (linux) server from scratch and hosting Next.js on it. On Digital Ocean you can use droplets. On AWS you can use EC2. Either way you are setting up a linux server. The only packages needed on the server are: ngnix, npm, node and pm2
Note: I made a couple of mistakes when trying to start the website using pm2. They are corrected in the video right away. I decided to keep the error and the correction in the video as I thought it is more helpful for you to see me first make the mistake and the correction, because they are very common.
Intro: 0:00
Server purchase: 2:43
Server setup: 6:04
SSH for pulling: 11:28
Create boiler plate Next.js: 14:00
Clone Next.js onto server: 16:30
NGINX config file: 18:29
Enable config file: 21:33
Launch app with pm2: 24:00
– pm2 mistake 1: 24:48 (make sure to cd into the app directory before launching)
– pm2 mistake 2: 26:02 (make sure to launch the app on the same port that’s in the config file)
Live next.js site: 27:02
Add domain to config file: 27:34 (also have access to DNS records on your domain name)
Add free SSL: 30:01
Setup auto-deployment: 31:33
– Add private SSH to GitHub: 35:18
– Add GitHub Actions with yml file: 36:21
–GIST—
Gists for reference to all commands and config files used in the video:
Server setup: https://gist.github.com/oelbaga/5019647715e68815c602ff05cff2416e#file-01-setup-nextjs-site-on-ubuntu-server-terminal-commands
nginx config file: https://gist.github.com/oelbaga/5019647715e68815c602ff05cff2416e#file-02-nginx-config-file-for-nextjs-site
yml file for auto deployment:
https://gist.github.com/oelbaga/5019647715e68815c602ff05cff2416e#file-04-github-actions-for-auto-deployment-deploy-yml
ssh steps for auto deployment:
https://gist.github.com/oelbaga/5019647715e68815c602ff05cff2416e#file-03-auto-deployment-from-github-to-ubuntu-server
CONNECT ON MY DISCORD COMMUNITY:
https://discord.gg/5zsdrxH8m8
SOCIALS:
Twitter: https://twitter.com/omarel
Website: https://www.omarel.com
LinkedIn: https://www.linkedin.com/in/omarelbaga
GitHub: https://github.com/oelbaga
by Digital CEO
linux dns server
sir i am facing this issue
ubuntu@13.200.235.21: Permission denied (publickey).
Error: Process completed with exit code 255.
You are back!! great news!
This is absolutely amazing… Been looking/waiting for this.
What about full stack with something like prisma?
Thank you!
mongodb in host bro !
Awesome tutorial! Any idea on how DigitalOcean pricing compares to AWS?
Your tutorials are absolute gold! Thank you so much! 😊