Run these commands (as SU) to update all dependencies and then reboot:
apt update
apt upgrade
apt autoremove
apt autoclean
reboot
install these packages:
apt install -y curl wget apt-transport-https git
create user for your project:
adduser APP_USER
run these commands to install nodejs:
cd ~
curl -sL https://deb.nodesource.com/setup_14.x -o nodesource_setup.sh
bash nodesource_setup.sh
apt install nodejs
rm nodesource_setup.sh
run this command:
apt install nginx
run this commands to add MySQL Repo:
wget http://repo.mysql.com/mysql-apt-config_0.8.14-1_all.deb
apt update
run this command to install MySQL:
apt install -y mysql-server
after that, run this command to configure it:
mysql_secure_installation
run this command to install MongoDB:
wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add -
echo "deb http://repo.mongodb.org/apt/debian buster/mongodb-org/4.4 main" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.4.list
apt update
apt install mongodb-org
run this command to set password for root:
mongo admin --eval 'db.createUser({ user:"root", pwd:"YOUR_PASSWORD", roles:[{role:"root", db:"admin"}]})'
after that go to this file:
nano /etc/mongodb.conf
and set auth
to true
:
auth=true
finally restart mongodb service
systemctl restart mongodb
run this command:
apt install redis-server
to set password for redis, go to this file:
nano /etc/redis/redis.conf
uncomment requirepass
and fill it with your password:
requirepass YOU_PASSWORD
run this command to install PM2:
npm install -g pm2
run this command to install yarn:
npm install -g yarn
remember you have to create a MySQL database for your project (with superuser).
run this command with SU:
mysql
and run these commands to create a database and a user for it:
CREATE DATABASE YOUR_DB_NAME COLLATE utf8_general_ci;
CREATE USER 'YOUR_DB_USERNAME'@'localhost' IDENTIFIED BY 'YOUR_DB_PASSWORD';
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, CREATE TEMPORARY TABLES, SHOW VIEW ON YOUR_DB_NAME.* TO 'YOUR_DB_USERNAME'@'localhost';
FLUSH PRIVILEGES;
if you want to proxy-forward your app with Nginx, copy these command in /etc/nginx/sites-available/default
:
server {
listen 80;
server_name myapp.com;
location / {
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_cache_bypass $http_upgrade;
}
}
1- install nginx-extras:
apt install nginx-extras
2- open /etc/nginx/nginx.conf
and turn off server_tokens
:
http {
more_set_headers "Server: Your_New_Server_Name";
server_tokens off;
}
3- restart nginx
:
systemctl restart nginx
login with your project user.
first of all upload your files (or pull from git):
git pull YOUR_REPOSITORY_ADDRESS
then install packages with your package manager (npm or yarn):
npm install
yarn install
set your ENVIROMENT variables (mostly in .env file):
nano .env
run your app with PM2:
pm2 start app.js --name your_app_name