Forked from marcuwynu23/vps-cmd-setup-node-mongodb.txt
Created
December 20, 2024 00:06
-
-
Save projectoperations/c6ea1ac2239d6e150a4e8d8047393d89 to your computer and use it in GitHub Desktop.
Setup VPS(ubuntu 2022) for web hosting and database hosting node.js express and mongodb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Working with nodejs-mongodb Project with Virtual Private Server (linux VPS) in Terminal | |
| ################################################ ssh to the vps ################################################################## | |
| # mongodb hosting vps | |
| ssh <username>@<ip address|domainname> | |
| ############################################## install nodejs and npm ############################################################# | |
| sudo apt install -y nodejs npm | |
| ########################################### install mongodb server ########## ##################################################### | |
| wget -qO - https://www.mongodb.org/static/pgp/server-6.0.asc | sudo apt-key add - | |
| sudo apt-get install gnupg | |
| wget -qO - https://www.mongodb.org/static/pgp/server-6.0.asc | sudo apt-key add - | |
| echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/6.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-6.0.list | |
| sudo apt-get update | |
| sudo apt-get install -y mongodb-org | |
| ########################################### install libssl dependency of mongodb #################################################### | |
| echo "deb http://security.ubuntu.com/ubuntu focal-security main" | sudo tee /etc/apt/sources.list.d/focal-security.list | |
| sudo apt-get update | |
| sudo apt-get install libssl1.1 | |
| sudo rm /etc/apt/sources.list.d/focal-security.list | |
| sudo apt-get install -y mongodb-org | |
| ###################################################### install npm forever ####################################################### | |
| sudo npm i -g forever | |
| ################################################## allowing important port in vps linux firewall ######################################## | |
| # if ufw is not installed | |
| sudo apt install ufw | |
| # note: know the important port that used connecting with your vps such as ssh port, you need to set it | |
| sudo ufw allow ssh | |
| #note: this port use in accessing vps dashboard in godaddy | |
| sudo ufw allow 2224/tcp | |
| # allow mongodb port in ufw | |
| sudo ufw allow 27017/tcp | |
| # allow http or https port | |
| sudo ufw allow https | |
| sudo ufw allow http | |
| sudo ufw enable | |
| sudo ufw reload | |
| # note: if the port you configure not working, restart the vps server in you dashboard | |
| ########################################################################################################################### | |
| # reconnect with the vps using ssh | |
| ############################################## run mongodb as services ########################################################## | |
| sudo service mongod start | |
| # set storage cache_size | |
| wiredTiger: | |
| engineConfig: | |
| configString: cache_size=600M | |
| ###################################### run nodejs as a foreground using forever ###################################################### | |
| sudo forever start app.js | |
| ##################################################### update nodejs repo ####################################################### | |
| cd kalapatid | |
| git pull origin main | |
| sudo forever restart app.js |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment