# Hi2Chat Beta Deployment Guide

## 1. DNS
Create A records:

```text
beta.hi2chat.com      -> YOUR_SERVER_IP
api.beta.hi2chat.com  -> YOUR_SERVER_IP
```

## 2. Server packages

```bash
sudo apt update
sudo apt install -y nginx mysql-server nodejs npm
sudo npm install -g pm2
```

Recommended Node version: 20 LTS.

## 3. Database

```sql
CREATE DATABASE hi2chat_beta CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'hi2chat_beta_user'@'localhost' IDENTIFIED BY 'CHANGE_THIS_DB_PASSWORD';
GRANT ALL PRIVILEGES ON hi2chat_beta.* TO 'hi2chat_beta_user'@'localhost';
FLUSH PRIVILEGES;
```

## 4. Upload project

```bash
sudo mkdir -p /var/www/hi2chat-beta
sudo chown -R $USER:$USER /var/www/hi2chat-beta
unzip hi2chat-enterprise-build-06.1-beta-ready.zip -d /var/www/hi2chat-beta/current
```

## 5. Backend env

```bash
cd /var/www/hi2chat-beta/current
cp .env.production.example .env.production
nano .env.production
```

Set real values for JWT secret, database and SMTP.

## 6. Frontend env

```bash
cd /var/www/hi2chat-beta/current/frontend
cp .env.production .env.production.local
```

Confirm:

```text
VITE_API_URL=https://api.beta.hi2chat.com/api/v1
VITE_SOCKET_URL=https://api.beta.hi2chat.com
```

## 7. Build frontend and backend

```bash
cd /var/www/hi2chat-beta/current
npm ci
npm run build

cd frontend
npm ci
npm run build
```

## 8. PM2

```bash
cd /var/www/hi2chat-beta/current
sudo mkdir -p /var/log/hi2chat-beta
pm2 start deploy/pm2/ecosystem.config.cjs
pm2 save
pm2 startup
```

## 9. Nginx

```bash
sudo cp deploy/nginx/beta.hi2chat.com.conf /etc/nginx/sites-available/
sudo cp deploy/nginx/api.beta.hi2chat.com.conf /etc/nginx/sites-available/
sudo ln -s /etc/nginx/sites-available/beta.hi2chat.com.conf /etc/nginx/sites-enabled/
sudo ln -s /etc/nginx/sites-available/api.beta.hi2chat.com.conf /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx
```

## 10. SSL

```bash
sudo apt install -y certbot python3-certbot-nginx
sudo certbot --nginx -d beta.hi2chat.com -d api.beta.hi2chat.com
```

## 11. Test

Open:

```text
https://beta.hi2chat.com
https://api.beta.hi2chat.com/api/docs
```

Create a beta account, login, then test Main Lobby.
