# Upload & deploy ke VPS AlmaLinux — seminar.bgtkntb.id

## Yang di-upload ke server

Upload **seluruh folder proyek** ke VPS, misalnya `/var/www/seminar-gtk`, **kecuali**:

| Jangan upload | Alasan |
|---------------|--------|
| `node_modules/` | Di-install di server dengan `npm ci` |
| `.next/` | Hasil build, dibuat di server |
| `.env.local` | Khusus development Mac |
| `PRD_*.md` | Opsional |

**Harus ikut:** `deploy/`, `app/`, `components/`, `lib/`, `public/`, `package.json`, `package-lock.json`, dll.

### Cara upload (pilih satu)

**ZIP dari Mac:**

```bash
cd /Users/imac05/Herd/landingseminar
zip -r seminar-gtk.zip . -x "node_modules/*" -x ".next/*" -x ".env.local" -x ".git/*"
scp seminar-gtk.zip user@IP_VPS:/var/www/
# Di VPS:
cd /var/www && unzip seminar-gtk.zip -d seminar-gtk && cd seminar-gtk
```

**Git:** `git clone` di VPS jika repo sudah di Git.

---

## Prasyarat VPS

- Node **20.9+** via nvm (`nvm use 20`)
- Apache **httpd** sudah terpasang
- DNS **seminar.bgtkntb.id** → A record ke IP VPS
- Bridge kuota `quota.php` tetap di server Simdiklat (sudah jalan)

---

## Instalasi otomatis (di VPS)

```bash
cd /var/www/seminar-gtk   # sesuaikan path
chmod +x deploy/setup-alma.sh
./deploy/setup-alma.sh
```

Script akan:

1. Memakai Node 20 dari nvm  
2. Menyalin `deploy/seminar.bgtkntb.id.env` → `.env.production`  
3. `npm ci` + `npm run build`  
4. Menjalankan PM2 pada port **3010**

---

## Apache (sudo)

Modul proxy (biasanya sudah ada di httpd):

```bash
sudo setsebool -P httpd_can_network_connect 1
sudo cp deploy/httpd-seminar.bgtkntb.id.conf /etc/httpd/conf.d/
sudo apachectl configtest
sudo systemctl reload httpd
```

Port **3010** dipilih agar tidak bentrok dengan aplikasi Node lain di **3000**. Jika 3010 bentrok, ubah `PORT=` di `deploy/seminar.bgtkntb.id.env` dan `ProxyPass` di file httpd agar sama.

**SSL:**

```bash
sudo dnf install -y certbot python3-certbot-apache
sudo certbot --apache -d seminar.bgtkntb.id
```

Edit `/etc/httpd/conf.d/seminar.bgtkntb.id.conf`: aktifkan blok `<VirtualHost *:443>`, aktifkan redirect HTTP→HTTPS di port 80.

---

## Cek setelah deploy

```bash
curl -s http://127.0.0.1:3010/api/health
curl -s https://seminar.bgtkntb.id/api/health
curl -s https://seminar.bgtkntb.id/api/quota/offline
pm2 logs seminar-gtk --lines 30
```

Browsers: buka https://seminar.bgtkntb.id di ponsel.

---

## Update versi baru

```bash
cd /var/www/seminar-gtk
# upload file baru atau git pull
source ~/.nvm/nvm.sh && nvm use 20
npm ci
npm run build
pm2 restart seminar-gtk
```

---

## File di folder `deploy/`

| File | Fungsi |
|------|--------|
| `seminar.bgtkntb.id.env` | Env production (domain + bridge kuota) |
| `httpd-seminar.bgtkntb.id.conf` | VirtualHost Apache |
| `ecosystem.config.cjs` | Konfigurasi PM2 |
| `setup-alma.sh` | Skrip instalasi sekali jalan |