cd .\.ssh\
rm .\known_hosts
ssh root@ipAddress
> yes > Enter Password from Email > Enter new Passwordssh root@ipAddress
> yesssh-keygen -t rsa -b 4096 -C "email"
=> Generate ssh key for private repocat path
=> Copy the ssh key path generated and paste it here to generate ssh keyssh @userNameipAddress
=> Log in your VPS by entering your Passworduser@hostName:/#
=> Logged in as thisroot@hostName:/#
=> Root as all Permissions, Dangerous to use thisadduser userName
=> Add a User, Type Passwordusermod -aG sudo userName
=> Give ROOT power to that User by making it sudo User, Can execute ROOT commands by using sudo beforesudo su
=> Login as ROOT user from any other usersu userName
=> Login as any other usersudo ufw app list
=> List of available applications, UFW acts as a Firewall like a Solder and a Wallsudo ufw status
=> Status of your Appsudo ufw allow OpenSSH
=> Allow this application, So that Solder allows yousudo ufw enable
=> Firewall becomes active, Solder activeexit
=> Disconnect Consolessh-keygen -t rsa
=> Press Enter for all/c/Users/manav/.ssh/id_rsa_dileName
=> Put it separately by giving seperate file namecat ~/.ssh/id_rsa.fileName.pub
=> Shows your Public Key, Copy itssh-copy-id root@IPAddress
=> To add the Key in your VPS, Or paste directly in Digital Ocean SSH Keyssh-add ~/.ssh/id_rsa_filename
=> Add this new file as SSH => Run this before eval "$(ssh-agent)"
if neededssh root@IPAddress
=> You will be logged in directlystart "" ssh root@IPAddress
=> Type this in that filecurl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -
=> Get Node JS from Node sourcesudo apt install nodejs
=> Install Node JSnode --version && npm --version
=> Check if it is installedcd ~
mkdir appname
cd appName/
=> Clone your code from GitHub or make a test filemkdir node nodsudo vi app.js
sudo vi app.js
=> Create this Folder const express = require("express");
const app = express();
const port = 3000;
app.get("/", (req, res) => {
res.send("Hello World!");
});
app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`);
});
npm install express
=> Install Expressnode app.js
sudo npm i pm2 -g
=> Install and use pm2 as a process managerpm2 start app.js
=> Start the applicationpm2 status
pm2 restart index.js
pm2 logs
pm2 flush
pm2 startup ubuntu
=> Start automatically at startsudo apt install nginx
=> Install Nginx as a reverse proxysudo vi /etc/nginx/sites-available/default
server{
server_name yourDomain www.yourDomain;
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_cache_bypass $http_upgrade;
}
}
sudo nginx -t
=> Check if everything is Oksudo service nginx restart
sudo add-apt-repository ppa:certbot/certbot
sudo apt-get update
sudo apt-get install python-certbot-nginx
sudo apt-get install certbot python3-certbot-nginx
=> If above command does not worksudo certbot --nginx -d yourdomain.com -d www.yourdomain.com
certbot renew --dry-run
=> Automatically renew after 90 dayssudo apt update
=> Update apt commandssudo apt install apache2 -y
=> It is a Web Serversudo ufw app list
=> Gives list of Apps that want to pass Firewallsudo ufw app info "appName"
=> Gives description about that Appsudo ufw allow in "appName"
=> Allow incoming traffic on required PORT for this Appsudo apt install mysql-server
=> Install MySQLsudo mysql
=> Opens MySQL terminalSELECT user, authentication_string, plugin, host from mysql.user;
=> Shows how ROOT is logging inALTER user 'root'@'localhost' identified with mysql_native_password by 'yourPassword';
=> Changes the authentication way for ROOT to given Password, Not RecommendedFLUSH PRIVILEGES:
exit
=> Close Terminalsudo mysql -p
=> Now you have to login using Passwordsudo apt install php libapache2-mod-php php-mysql
=> Install PHP and some other Modulessudo nano /etc/apache2/mods-enabled/dir.conf
sudo service apache2 restart
=> Restartcd /var/www
=> All Websites are by default in this foldercd /html
=> Contains index.html file of Apache by default which is being served on your IP Addresssudo nano index.php
=> Create this File and write the given code to serve this instead <?php
phpinfo();
?>
sudo service apache2 restart
=> Restartsudo apt install phpmyadmin php-mbstring php-gettext
sudo phpenmod mbstring
=> Enables Modulessudo service apache2 restart
=> Restartsudo mysql -p
=> Logincreate user 'userName'@'localhost' identified by 'yourPassword';
=> Create a new user to Login in phpMyAdmin instead of ROOTgrant all privileges on *.* to 'userName'@'localhost' with grant option;
=> Give ROOT power to that usercd /var/www
sudo mkdir fileName
=> Create this Filels -lart
=> List with some informationsudo chown -R $USER:$USER fileName1
=> Make current user owner of the file instead of ROOTls -lart
=> List with some informationcd fileName1/
sudo nano index.html
=> Create this file and edit using Nanocd /etc/apache2/sites-available/
=> Available Sites by Defaultls
=> 2 files will be there by default, 000-default.conf & default-ssl.confsudo cp 000-default.conf fileName2.conf
=> Copy that in a new filesudo nano fileName2.conf
=> Open in nano ServerAdmin email@address
ServerName domainName
ServerAlias www.domainName
DocumentRoot /var/www/fileName1
sudo a2ensite fileName2.conf
=> Enable this Sitesudo a2dissite 000-default.conf
=> Disable old sitesudo service apache2 restart
=> Restartsudo apache2ctl configtest
=> Checks if configuration is rightsudo apt install libapache2-mod-wsgi-py3
=> Mod of Apache that serves Python files using wsgicd /var/www
mkdir flaskapp
cd flaskapp/
mkdir flaskapp
cd flaskapp/
=> You are in /var/www/flaskapp/flaskappsudo apt install python3-pip
pip3 install virtualenv
=> Install Virtual Environment using pipsudo virtualenv venv
=> Virtual Environment createdsource venv/bin/activate
=> (venv) will be written before user@hostNamepip3 install flask requests panda flask-sqlalchemy
=> Install anything you wantpython
=> Python interpreter active, You can write python code hereexit()
=> Exit Editordeactivate
=> Virtual Environment Deactivated (venv) removedcd /etc/apache2/sites-available/
sudo cp 000-default.conf fileName.conf
=> Copy that in a new filesudo nano fileName2.conf
=> Open in nano ServerName domainName
ServerAdmin email@address
WSGIScriptAlias / /var/www/flaskapp/flaskapp.wsgi
<Directory /var/www/flaskapp/flaskapp/>
Order allow,deny
Allow from all
</Directory>
Alias /static /var/www/flaskapp/flaskapp/static
<Directory /var/www/flaskapp/flaskapp/static>
Order allow,deny
Allow from all
</Directory>
DocumentRoot /var/www/flaskapp
LogLevel warn
sudo a2ensite flaskapp.conf
sudo service apache2 restart
=> If there is no problem then this will worksudo nano flaskapp.wsgi
#!/usr/bin/python
activate_this = '/var/www/flaskapp/flaskapp/venv/bin/activate_this.py'
exec(open(activate_this).read(), dict(__file__=activate_this))
import sys
import logging
logging.basicConfig(stream=sys.stderr)
sys.path.insert(0, "/var/www/flaskapp/")
from flaskapp import app as application
application.secret_key = 'Add-my-secret-1234-key!@$$%^&*(sdfsdf643535##$$'
cd flaskapp/
vim __init__.py
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return "Hello, World!"
python3 __init__.py
=> Run this filesudo service apache2 restart
cd var/log/apache2/
cat error.log
=> Shows error/var/www/html
=> It contains the actual Web Content, By default it contains Apache page, Can change it in Configuration file/etc/apache2
=> The Apache configuration directory/etc/apache2/apache2.conf
=> The main Apache Configuration File/etc/apache2/ports.conf
=> The file specifies the ports that Apache will listen on. By default, Apache listen on port 80 and additionally listens on post 443 when a module providing SSL capabilities is enabled/etc/apache2/sites-available/
=> The directory where per-site virtual hosts can be stored, Which directory to serve for different domains, Apache will not use the configuration files found in this directory unless they are linked to the sites-enabled directory/etc/apache2/sites-enabled/
=> The directory where per-site virtual hosts are stored, These are created by linking to configuration files found in sites-available directory with the a2ensite, Apache reads the configuration files and links found in this directory when it starts or reloads to compile a complete configuration/var/log/apache2/access.log
=> By default, every request to your web server is recorded in this log file unless Apache is configured to do otherwise/var/log/apache2/error.log
=> By default, all error are recorded in this file. The LogLevel directive in the Apache configuration specifies how much detail the error logs will contain