Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save dosanauthor/267296ef9eccfd3438cb5fa84f396546 to your computer and use it in GitHub Desktop.
Save dosanauthor/267296ef9eccfd3438cb5fa84f396546 to your computer and use it in GitHub Desktop.
Deploying PDF Tools Nextjs app On VPS using Docker, Ubuntu Os, Github, Nginx and Let's Encrypt SSL Certificates
Get Source code: https://codecanyon.net/item/pdf-tools-high-quality-pdf-tools-nextjs-react-web-application/44924651
WARNING: This item is exclusively sold on CodeCanyon under Envato Market licenses. Please do not purchase it from other sources, as they might be attempting to scam you.
=============================Create private Github Repository===========================================================
#Create private github repository for the project and push the project from local machine to the github repository
==============================Creating a Virtual Private Server (VPS)=========================================
In this video I will use Digitalocean droplets, but the deployment steps are the same for every VPS.
Once you have the necessary information such as the VPS IP address, login password, and domain name,
you can follow this video tutorial to deploy your application on your VPS.
==============================DNS Configuration================================================================
Add these two records to your DNS records:
Record 01:
Type: A Record, Host: @, Value: ip_address
Record 02:
Type: CNAME Record, Host: www, Value: domain-name
================================Login to VPS===================================================================
#Open terminal, and type the fllowing command:
/ ssh root@ip_address
#Type 'yes' If you get the message: The authenticity of host 'host_IP_address (host_IP_address)' can't be established.
#Enter your password
#You are now connected to your VPS.
==============================Server Setup and Configuration===================================================
/ sudo apt update && apt upgrade
/ sudo apt install nginx certbot python3-certbot-nginx ufw
/ sudo ufw allow "Nginx Full"
/ ufw allow OpenSSH
/ ufw enable
==============================Docker Installation===============================================================
#Check if docker is already installed
/ docker version
#If not found type the next commands to install it.
#Installing Docker on VPS
/ sudo apt install apt-transport-https ca-certificates curl software-properties-common
/ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
/ echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
/ sudo apt update
/ sudo apt install docker-ce docker-ce-cli containerd.io
/ sudo systemctl start docker
/ sudo usermod -aG docker $USER
/ docker version
==============================Github Authentication on VPS via SSH======================================================
#Generate an SSH key pair on the VPS using the command:
/ ssh-keygen
#The command will prompt you to specify a location for the key pair, and to enter a passphrase if you wish to have one. The default location is usually fine, so you can just press Enter to accept it.
#Once the key pair is generated, you can view the public key by typing the following command cat /path/to/public_key
/ cat ~/.ssh/id_rsa.pub
#Copy the entire public key to your clipboard.
#Log in to your GitHub account in a web browser.
#Click on your profile icon in the top right corner of the page and select "Settings" from the dropdown menu.
#In the left sidebar, select "SSH and GPG keys".
#Click the "New SSH key" button.
#Give your new key a descriptive title in the "Title" field.
#Paste the public key that you copied earlier into the "Key" field.
#Click the "Add SSH key" button.
#Your VPS is now authorized to access your GitHub account via SSH. When you clone or push to a repository using SSH, Git will automatically use your SSH key for authentication, and you won't be prompted for a username or password.
==============================Uploading files to server using Github==============================================
#Navigate to the directory /var/www/ in server using the command:
/ cd /var/www
#Cloning repository to server uinsing the command:
/var/www# git clone git@github.com:your-username/your-repository-name.git
#Replace "your-username" with your GitHub username, and "your-repository-name" with the name of the repository you want to clone.
==============================Building the docker image & creating the container==================================
#Afer cloning the project file from local machine to server, type the folowing commands to build docker image and create a container:
/var/www# cd pdf-tools-all-in-one
/var/www/pdf-tools-all-in-one# docker build -t pdftoolsimage .
/var/www/pdf-tools-all-in-one# docker run -d -p 8080:3000 --name pdftools_c pdftoolsimage
#The app is now running on port 8080
==============================Nginx Configuration==================================
/var/www/pdf-tools-all-in-one# cd /etc/nginx/
/etc/nginx# ls
/etc/nginx# cd sites-available
/etc/nginx/sites-available# ls
#Make sure to change domain-name with your domain name
/etc/nginx/sites-available# touch domain-name
/etc/nginx/sites-available# ls
#Make sure to change domain-name with your domain name
/etc/nginx/sites-available# nano domain-name
#Copy and past this config in domain-name file, make sure to change domain-name.com with your domain name
server {
listen 80;
server_name domain-name.com www.domain-name.com;
location / {
proxy_pass http://localhost:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
#Save file CTRL+S
#Exit file CTRL+X
/etc/nginx/sites-available# rm default
/etc/nginx/sites-available# cd ..
#Make sure to change domain-name with your domain name
/etc/nginx# sudo ln -s /etc/nginx/sites-available/domain-name /etc/nginx/sites-enabled/
/etc/nginx# ls
/etc/nginx# cd sites-enabled
/etc/nginx/sites-enabled# ls
/etc/nginx/sites-enabled# rm default
/etc/nginx/sites-enabled# ls
/etc/nginx/sites-enabled# cd ..
#Open the Nginx configuration file in a text editor.
/etc/nginx# nano nginx.conf
#Inside the http block, add or modify the client_max_body_size directive to set the desired limit.
client_max_body_size 1G;
#Save Nginx configuration file CTRL+S
#Exit Nginx configuration file CTRL+X
#Testing Nginx configuration for errors
/etc/nginx# nginx -t
#Restart the Nginx service to apply the new configuration
/etc/nginx# systemctl restart nginx
============================Creating Let's Encrypt SSL Certificates=======================
#Make sure to change domain-name.com with your domain name
/etc/nginx# sudo certbot --nginx -d domain-name.com -d www.domain-name.com
============================Cloudflare=======================
#After let's encrypt certificates are installed successfully you can add your domain to cloudflare.
=========================================================================================
========================= Update Project & Redeploy App==================================
=========================================================================================
#After making changes to the project, follow these steps to redeploy the PDF Tools app.
==========================Pushing the updated project to Github========================================
#On your local machine, nagivate to project directory, open a terminal and type the following commands:
#Commit your changes to your local Git repository using the command:
git add .
git commit -m "Updated app with new features"
#Push your changes to the GitHub repository using the command:
git push origin main
==========================Login to VPS========================================
#Open terminal, and type the fllowing command:
/ ssh root@ip_address
#Type 'yes' If you get the message: The authenticity of host 'host_IP_address (host_IP_address)' can't be established.
#Enter your password
#You are now connected to your VPS.
==========================Updating project on server========================================
#On your VPS, navigate to the project directory and pull the changes from the GitHub repository using the commands:
/ cd /var/www/pdf-tools-all-in-one
/var/www/pdf-tools-all-in-one# git pull
==========================Rebuilding the Docker image========================================
#In project directory, Rebuild the Docker image with the updated code by running the command:
/var/www/pdf-tools-all-in-one# docker build -t pdftoolsimage .
#Stop the running container using the following command:
/var/www/pdf-tools-all-in-one# docker stop pdftools_c
#Remove the existing container using the following command:
/var/www/pdf-tools-all-in-one# docker container rm pdftools_c
#Start a new container with the updated image using the following command:
/var/www/pdf-tools-all-in-one# docker run -d -p 8080:3000 --name pdftools_c pdftoolsimage
#Your updated app should now be redeployed and running in the new container on your VPS.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment