Deploy MERN App with Hostinger VPS in 10 Steps || Ubuntu || Git Actions
HTML-код
- Опубликовано: 30 мар 2024
- Welcome to this step-by-step tutorial on how to deploy your MERN (MongoDB, Express.js, React, Node.js) stack application on a Hostinger VPS with Ubuntu OS. By the end of this video, you'll have your application running smoothly on a secure and optimized server.
1. Connecting to Your VPS Using SSH - Starting with establishing a secure connection to your VPS, ensuring a safe and exclusive access environment for your deployment.
2. Updating the VPS - Keeping your server up to date with the latest packages and security patches to ensure optimal performance and security.
sudo apt-get update and sudo apt-get upgrade
3. INSTALL NODE.JS:
curl o raw.githubusercontent.com/nvm... | bash
source ~/.bashrc
nvm install node # Install the latest version of Node.js
4. INSTALL MONGODB
wget -qO - www.mongodb.org/static/pgp/se... | sudo apt-key add -
echo "deb [ arch=amd64,arm64 ] repo.mongodb.org/apt/ubuntu focal/mongodb-org/4.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.4.list
sudo apt update
sudo apt install mongodb-org -y
sudo systemctl start mongod
sudo systemctl enable mongod
Install git:
sudo apt-get install git-all
5. INSTALL PM2
npm install pm2@latest -g
6. INSTALL NGINX
sudo apt install nginx -y
7. Configure NGINX as a reverse proxy for your application. Create and edit a new configuration file:
sudo nano /etc/nginx/sites-available/marvel.boltluna.io
server {
listen 80;
server_name marvel.boltluna.io;
location / {
proxy_pass localhost:10000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
8. Enable the configuration by creating a symlink and then test and reload NGINX:
sudo ln -s /etc/nginx/sites-available/marvel.boltluna.io /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx
9. Secure Your Application with SSL (HTTPS)
Install Certbot and the NGINX plugin:
sudo snap install --classic certbot
sudo ln -s /snap/bin/certbot /usr/bin/certbot
sudo certbot --nginx -d marvel.boltluna.io
10. Open Necessary Ports in the Firewall
sudo ufw allow ssh
sudo ufw allow http
sudo ufw allow https
sudo ufw enable
sudo ufw status
#MERNStack #WebDevelopment #FullStackDeveloper #CodingTutorial #HostingerVPS #UbuntuServer #NodeJS #ReactJS #MongoDB #NginxProxy #DevOps #WebHosting #SSLSetup #JavaScript #PM2 #CodingLife #TechTutorial #ProgrammerLife #WebAppDeployment #SecureHosting Наука
Bro u are a life saver. I have been trying to deploy my app in hostinger, watched so many videos and I get some ideas from there but this one you really did a good job here, this one is a great video on hosting. And I am expecting some help if I ended up in some errors.
omg bro, you were so helpful for me. thanks for making this video.
Thank you. Appreciate it!
How to deploy branch for example staging branch. i believe this tutorial deploy for the main branch. Please make a video for it
Hey there, thankx for viewing the video. From what i understand, you're having a difficult time getting the git branch to go from staging to main branch.
I'm not sure if i can make a video on just this but i can attempt to walk you through the steps here. Try following this in order:
- On you local machine, run the command:
- git checkout staging
- git checkout main
- git merge staging (this will switch to the main branch and merge the changes from the staging branch)
- git add .
- git commit -m "Merged staging into main"
- git push origin main (this will push the updated main branch to the remote repository)
- clone your repo by using "git clone" command and following the steps in the description.
This should work. If not let me know and we can debug it together.
bro Thanks alot I found this video super helpfully , I have bug after command : sudo systemctl reload nginx : Error : nginx.service is not active, cannot reload., do you have any idea of what goes wrong on my issue . thanks bro
Hey there, thankx for watching the video. Sorry you got bug. Try debugging using these steps and let me know how it goes (do this in order):
- sudo apt update
- sudo apt install nginx
- sudo systemctl status nginx (this will check the current status of the nginx service and let you know if its active or not and its current status)
- sudo nginx -t (this checks to see if theres any syntax error)
If this doesnt work, let me know and we can try debugging it again together.
thanks for sharing this useful video, can we host 2 websites on the same server?
btw: you remind me of bob marley
Lol thanks. Yes you can host multiple websites on the same server. You just have to create a directory for that specific application, create a subdomain pointing to your VPS, and then run the same commands that were shown.
Thanks for the video it helped me a lot but I do have a few questions the first one is : do I have the purchase the premium shared hosting as well with the vps to host the mern app ? And the last one is: do I need a mongodb production plan to deploy to production? Thank you again
Thanx for watching. Glad you found it helpful. To answer your questions: No.Getting the premium shared hosting gives you access to the cpanel that you can use to deploy front end react applications, meaning no back end (Node.js/express.js) code is involved. Fro example a PHP server code can be deployed with a front end reactjs code using the cpanel which you get from shared hosting.
A vps allows you to deploy both a full stack and/or a back end/front end application directly to a private server therefore if you are looking to deploy a full stack application, a VPS is recommended as shared hosting doesn't afford you the luxury of deploying the node.js backend.
No. You can use a shared hosting like I do in other projects where I use a mongo database to attach to my project. If you watch any of my MURN project applications, you will see how I create this database. I only use free tier applications on my projects till date.
Hope this helps and thankx for watching.
@@Akin_37 thank you I really appreciate that 👏👍👍👍thanks for replying
If you had any changes to the repo on your local repo and push it to github. How do you update inside the vps hosting?
Hey ... I'm guessing you're talking about after cloning the Repo within the VPS. If so, you can use the command "git pull" to update the repo after cloning. Another way would be to create CI/CD pipeline to auto pull anything that is pushed to github.
I haven't created a video on the latter, but I probably will sometime in the future. Thankx
@@Akin_37 please make it the tutorial for this CI/CD pipeline with github
I can’t stop thanking you homie but I have one more question the project that I’m working on has an admin folder Running on a different port number so how can I do that as well please
No problem. When you say admin folder running on a different port, can you elaborate more on the architecture of your project? Why is it on a different port? or do you mean a different route? Just want to know more before I am able to answer your question.