Deployment - Terminal

React App Hosting => Using Nginx & FileZilla


  • Adding Domain
    • Open Windows PowerShell
    • ssh root@ipAddress => To login with SSH IP address
    • yes => Permanently add it to list of known hosts
    • sudo apt update => Install all the Package possible to install
    • sudo apt install nginx => Install Nginx
    • sudo ufw app list
    • sudo ufw allow 'Nginx Full' => You can now go to your server's IP address to check if Nginx is installed successfully
  • Add Files to IP Address using FileZilla
    • Log in to FileZilla
    • /var/www/html
    • sudo mkdir -p /path/www/domainaname/folderName => To create folders and nested folders in the given path
    • cd /etc/apache2/sites-available/ => Virtual Host
    • vim fileName => Edit file and Save & Exit
    • cp folderName folderName.conf
    • sudo a2ensite folderName => To enable folder
    • Delete the .html file > Transfer all files inside the "build" folder here
  • Add Domain
    • Buy a Domain > Records
    • Type = A > Edit
    • Points To = IP Address > Save
  • To Direct every request to index.html
    • cd /etc/nginx/sites-available/
    • ls => You will see a "default" folder
    • vim default
    • Under Server_name > location => Comment out "try_files $url $url/ -404" > Uncomment "try_files $url /index.html"
    • sudo service nginx restart
  • Enable HTTPS
    • sudo apt-get install certbot
    • apt-get install python3-certbot-nginx > Y
    • nginx -t && nginx -s reload => Text is successful message will appear
    • sudo certbot --nginx -d domainName -d www.domainName > Enter email address > A > N > 2
  • Update Files in FileZilla
    • Log in to FileZilla
    • /var/www/html => Transfer all files inside the "build" folder here and replace the older files
    • sudo service nginx restart

Single file Node JS App


  • ssh root@ipAddress => To login with ssh ipaddress after creating the droplet (Choose ssh instead of password)
  • yes => Permanently add it to list of known hosts
  • apt update => Install all the Package possible to install
  • curl -sL https://deb.nodesource.com/setup_14.x |sudo -E bash * => Download nodejs from Nodesource. NodeSource is a company which providesenterprise-grade Node support and maintains a repository containing the latest versions of Node.js
  • sudo apt-get install -y nodejs => Install nodejs
  • node --version && npm --version => Check the installation of node and npm
  • ls
  • cd /home
  • mkdir nodeApp => Make folder in /home named nodeApp
  • sudo vi app.js => Create an app and Paste your code
  • esc + w + q => Save and Quit vim
  • npm init => In the nodeApp folder, Fill the fields, package.json is created
  • vim package.json => To open this (not needed)
  • npm i express => Install express
  • node app.js => Check if this app is running
  • sudo npm i pm2 -g => Install and use pm2 as a process manager
  • pm2 start app.js => Start the application
  • ufw allow portNumber
  • sudo apt install nginx => Install Nginx
  • y
  • sudo vi /etc/nginx/sites-available/nodeApp -=>Create a conf file for our Nodejs app in /homenodeApp
    • server{ server_name ipAddress; 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 ln -s /etc/nginx/sites-available/nodeApp /etcnginx/sites-enabled => Activate this configuration
  • sudo service nginx restart => Go to your IP Address

Upload your Project using fileZilla


  • ssh root@ipAddress => To login with ssh ipaddress after creating the droplet (Choose ssh instead of password)
  • yes => Permanently add it to list of known hosts
  • apt update => Install all the Package possible to install
  • curl -sL https://deb.nodesource.com/setup_14.x |sudo -E bash * => Download nodejs from Nodesource. NodeSource is a company which providesenterprise-grade Node support and maintains a repository containing the latest versions of Node.js
  • sudo apt-get install -y nodejs => Install nodejs
  • node --version && npm --version => Check theinstallation of node and npm
  • Open fileZilla > Go to /home > Create newDirectory nodeapp > Upload your files here (without node_modules)
  • Go back to terminal
  • cd /home
  • cd /nodeapp
  • npm install
  • sudo npm i pm2 -g => Install and use pm2 as a process manager
  • pm2 start app.js => Start the application
  • ufw allow portNumber
  • sudo apt install nginx => Install Nginx
  • y
  • sudo vi /etc/nginx/sites-available/nodeApp -=>Create a conf file for our Nodejs app in /homenodeApp
    • server{ server_name ipAddress; 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 ln -s /etc/nginx/sites-available/nodeApp /etcnginx/sites-enabled => Activate this configuration
  • cd /etc/nginx/sites-enabled/
  • ls
  • rm default
  • sudo service nginx restart
  • Go to your IP Address

Virtual Host


  • apt install nodejs => Run node.js application forproduction on Ubuntu using Nginx server
  • apt install npm
  • sudo apt install build-essential => Install essential like gcc to compile
  • mkdir folderName => Make folder /home/nodeappindex.js
  • vim fileName => Insert Code
  • node index.js => To run file on local host
  • ufw allow port => Allow other devices to openthis port
  • curl localhost:port => Open a duplicate sessionwhich will open in same server
  • vim index.js => Change hostname='ipAddress';
  • node index.js & => File will run in background but close if you close putty
  • sudo npm install pm2@latest -g => Install pm2
  • pm2 examples
  • pm2 start index.js --name appName => Start indexjs with an app, Will run even if you close server
  • pm2 startup systemd => Program will run even if you reboot system
  • pm2 save => Saves all the process
  • pm2 ls
  • pm2 stop appName => To stop running app
  • pm2 start appName => To start stopped app
  • reboot => To reboot
  • sudo apt install apache2 => Run node.js application for production on Ubuntu using Apacheserver
  • sudo a2dissite file.conf => To disable site
  • sudo service apache2 restart => To activate new configuration
  • sudo a2enmod proxy proxy_http rewrite headers expires => Install these Modules and restart again
  • vim file.conf => Change Servername & ServerAlias to your domain
  • sudo a2ensite file.conf => Start program andRestart server
  • pm2 ls
  • pm2
  • pm2 example
  • curl localhost:port => Run your app
  • pm2 restart appName

Wordpress


  • ssh root@ipAdress
  • password
  • cd /var/www/html
  • ls
  • vim.htaccess => Edit this file to increse size of wordpress file that you can upload
  • php_value upload_max_filesize 100M => Paste this for increse upload size up to 100mb php_value post_max_size 100M php_value max_execution_time 300 php_value max_input_time 300

Apache


  • Open FTP Client
  • /home
  • Click Create Directory > folderName
  • Copy node modules here
  • Open PuTTy Configuration
  • Enter IP Address > Click Open
  • Enter login as: root & password
  • cd home/foldername
  • npm install
  • ufw allow 8000
  • Install MongoDB on Ubuntu
  • sudo apt install -y mongodb
  • node app.js => Application started on the givenport
  • mongo
  • show dbs
  • use folterName => contactDance
  • db.contacts.find() => To check if the filled formdata has been updated
  • exit
  • node app.js => Again start app after exit
  • pm2 list
  • pm2 start app.js --name " "
  • pm2 save
  • cd /etc/apache2/sites-available/
  • vim file.conf => Direct it to your port
  • sudo service apache2 restart
  • sudo add-apt-repository ppa:certbot/certbot -=>Get SSL certificate
  • sudo apt install python-certbot-apache => Bot to automatically update certificate
  • sudo apache2ctl configtest => To cheack yourapache configuration
  • sudo ufw status => Allowing https though yourfirewall
  • sudo ufw allow 'Apache Full'
  • sudo ufw delete allow 'Apache'
  • sudo ufw allow 'OpenSSH'
  • sudo certbot --apache -d your_domain -d wwwyour_domain

Deployment of MERN Stack App on Heroku


  • Install GIT & Heroku CLI
  • Terminal
    • heroku --version => Check
    • heroku login => Will open Browser
  • Add these commands
    • In the Backend main server file
      • const PORT = process.env.PORT || 5000 => Add this Port in the backend App so that Heroku can give any available Port
      • const mongoURI = process.env.MONGODB_URI || "yourString" => Add this for mongoose.connect function
      • After Build process => Serve the Build folder when Heroku is running
        if (process.env.NODE_ENV === "production") {
            app.use(express.static("folderPath"));
        }
        
    • In backend package.json inside scripts
      • "start": "node index.js" => Helps Heroku runs the server file if needed
      • "build": "cd path && npm run build" => So that Build process runs when App is on cloud
      • "processName": "cd path && npm install" => Installs npm modules before running above command
      • "heroku-postbuild": "npm run processName && npm run build" => In built heroku function that will run the above two commands in order
  • Terminal
    • rm -rf .git => Removes .git folder, Go to that folder and run this command, Subfolders should not have .git folder
    • git init => Initialize git in the root folder
    • git status => Check which files are selected to upload
    • heroku create appName => Creates your App
    • heroku addons:create mongolab:sandbox => This will add this Add-on
    • heroku addons --all => Your created app should be under Owning App column
    • git add -A => Add everything to Git
    • git commit -m "yourMessage" => Commit to Git
    • heroku local => Runs your App locally as it would in Heroku
    • git push heroku master => Push to Heroku
    • heroku open => Open the App in Browser
  • Connect with GitHub and Enable automatic Deployment
    • Create a new Repo and Copy the SSH key
    • git remote add origin repoSSh
    • git remote -v => Check if connected
    • git push origin master => Push to GitHub
    • Open your Heroku App > Deploy > Connect to GitHub > Search for the Repo > Connect > Enable Automatic Deploys
Share: