Deploy backend

Update

sudo apt-get update -y
sudo apt-get upgrade -y

Install git, nodejs, curl, yarn

sudo apt-get install git nodejs npm curl
npm install -g yarn
curl -sL https://deb.nodesource.com/setup_10.x -o nodesource_setup.sh
sudo bash nodesource_setup.sh
sudo apt install nodejs

Check version

git --version
nodejs --version
yarn --version

Install php,…

sudo apt-get install php7.2 php7.2-fpm php7.2-mysql php7.2-curl php7.2-gd php7.2-mbstring php7.2-xml php7.2-xmlrpc php-zip

Install composer

sudo apt install composer

Install database

// ---------MYSQL----------
sudo apt install mysql-client-core-5.7
sudo apt install mysql-server
sudo systemctl status mysql

Install project

sudo mkdir /var/www
git clone https://github.com/thaycacac.git
cd thaycacac
composer install
yarn

Create database

mysql -u root -p
CREATE DATABASE thaycacac DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
GRANT ALL ON thaycacac.* TO 'thaycacacuser'@'localhost' IDENTIFIED BY '123456';
use thaycacac;
source data.sql;

Config file .env

touch .env
nano .env
DB_HOST=127.0.0.1
DB_NAME=thaycacac
DB_USER=thaycacacuser
DB_PASSWORD=123456

Install web server (Caddy)

sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-stable.list
sudo apt update
sudo apt install caddy=2.3.0

sudo chmod 777 /var/www/html/.../public/uploads/...
  • Config web server
kungfutech.edu.vn, kungfutech.edu.vn:80 {
  tls thaycacac@gmail.com
  encode gzip
  reverse_proxy localhost:7985
}

api.kungfutech.edu.vn {
  header Cache-Control max-age=31536000
  header Strict-Transport-Security max-age=31536000
  header Referrer-Policy no-referrer-when-downgrade
  header X-Frame-Options DENY
  header X-Content-Type-Options nosniff
  root * /var/www/stech.edu.vn.back/public
  php_fastcgi unix//run/php/php7.2-fpm.sock
  encode gzip
  file_server
}

www.kungfutech.edu.vn {
   redir https://kungfutech.edu.vn {uri}
}

http://kungfutech.edu.vn {
  redir https://{host}{uri}
}

Restart web server

sudo systemctl restart caddy

Deploy nuxt

Install yarn,git,…and build project

yarn build
yarn start
```

Install pm2

```ssh
npm install pm2 -g
pm2 start yarn -- start

Export sql

mysql -u root
FLUSH PRIVILEGES;
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
mysqldump -u root -p thaycacac > data.sql

CI/CD

Gen SSH Key

mkdir -p $HOME/.ssh
chmod 0700 $HOME/.ssh
ssh-keygen
vim /root/.ssh/id_rsa.pub

Add SSH Key

Set repo:

git remote set-url origin git@github.com:

CD Frontend

name: CD
on:
  push:
    branches:
      - production
      - master
      - main
  schedule:
    - cron: '* 6 * * *'

jobs:
  ci-test:
    runs-on: ubuntu-18.04
    strategy:
      matrix:
        node-version: [14.x]
    steps:
    - uses: actions/checkout@v2

    - name: Deploy
      uses: appleboy/ssh-action@master
      with:
        host: $
        password: $
        username: root
        script: cd /var/www/stech.edu.vn
          && git pull
          && yarn
          && yarn build
          && pm2 restart yarn