DEV Community

Cover image for Setup VPS server with Cpanel for Nodejs Application (DNS, Mail)
Nurul Islam Rimon
Nurul Islam Rimon

Posted on β€’ Edited on

Setup VPS server with Cpanel for Nodejs Application (DNS, Mail)

connect to the terminal using your creadentials and install dependencies

  • example
ssh root@192.168.5.10
Enter fullscreen mode Exit fullscreen mode
  • update & install Hestiacp
sudo apt update && sudo apt upgrade
sudo apt install curl
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
wget https://raw.githubusercontent.com/hestiacp/hestiacp/release/install/hst-install.sh
sudo groupdel admin
bash hst-install.sh
Enter fullscreen mode Exit fullscreen mode

** If hestiacp installed successfully it will provide a credential to login in the Cpanel

  • example:

Admin URL: https://vmi2311142.contaboserver.net:8083

Backup URL: https://82.192.71.175:8083

Username: admin

Password: 5vFZn4jEx8Qowh7w

visit admin or backup url and login with username & password

  • create new user and create web for your application
    • example: bdcommerce.app

Image description

  • add ssl and alias from edit domain
    • example (alias): www.bdcommerce.app

open new terminal & connect: sftp remote-user@remote-server-ip (then your password)

  • if connected you can upload any file using: put
    • example:
sftp root@82.197.71.175  (password)
put your-file-path
Enter fullscreen mode Exit fullscreen mode
  • close connection
exit
Enter fullscreen mode Exit fullscreen mode

connect to the terminal again: ssh remote-user@remote-server-ip (then your password) and install node, npm and pm2

nvm install --lts
npm i pm2 -g
Enter fullscreen mode Exit fullscreen mode
  • now unzip the files
    • example:
unzip app.zip
Enter fullscreen mode Exit fullscreen mode
  • move folders to the domain path
    • example:
mv file-path/* new-path
Enter fullscreen mode Exit fullscreen mode
  • Now go to the file path
    • example:
cd /home/file-path
Enter fullscreen mode Exit fullscreen mode
  • install all dependencies
    • example:
npm i
Enter fullscreen mode Exit fullscreen mode
  • run the application using pm2
    • example:
pm2 start npm --name api -- start
Enter fullscreen mode Exit fullscreen mode
  • check the server's output
    • example:
curl localhost:5000
Enter fullscreen mode Exit fullscreen mode
  • config domain first go to the nginx config file by Hestia for your app
    • example (replace with your path-name):
nano /home/bdcommerce/conf/web/bdcommerce.app/nginx.conf
Enter fullscreen mode Exit fullscreen mode
  • replace proxy_pass with your running port
    • example:
proxy_pass http://localhost:5000;
Enter fullscreen mode Exit fullscreen mode

** save the file 'ctrl+o' then 'enter' then 'ctrl+x'

  • config ssl domain
    • example:
nano /home/bdcommerce/conf/web/bdcommerce.app/nginx.ssl.conf
Enter fullscreen mode Exit fullscreen mode
  • replace proxy_pass with your running port
    • example:
proxy_pass http://localhost:5000;
Enter fullscreen mode Exit fullscreen mode

** save the file 'ctrl+o' then 'enter' then 'ctrl+x'

  • Restart the nginx server
sudo systemctl restart nginx

Enter fullscreen mode Exit fullscreen mode
  • check domain if proxy is working or not
    • example: curl bdcommerce.app

Note: If everything is working then make sure HestiaCP will not change the Nginx config:

chattr +i /home/bdcommerce/conf/web/bdcommerce.app/nginx.conf
chattr +i /home/bdcommerce/conf/web/bdcommerce.app/nginx.ssl.conf
Enter fullscreen mode Exit fullscreen mode

Check attribute if ---i--- exit that means it's immutable

lsattr /home/bdcommerce/conf/web/bdcommerce.app/

Enter fullscreen mode Exit fullscreen mode

Thanks πŸ’š
N I Rimon

Top comments (0)

Sentry image

See why 4M developers consider Sentry, β€œnot bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

πŸ‘‹ Kindness is contagious

Please leave a ❀️ or a friendly comment on this post if you found it helpful!

Okay