# 🚀 Quick Deployment Guide

## Setup Pertama Kali di cPanel

### 1. Clone Repository
```bash
# Di cPanel → Git™ Version Control
Repository URL: https://github.com/YOUR_USERNAME/cbtQ.git
Branch: master
Directory: cbtQ
```

### 2. Setup Document Root
```bash
# Point domain/subdomain ke:
/home/USER/public_html/cbtQ/public
```

### 3. Copy .htaccess
```bash
cp .htaccess.production public/.htaccess
```

### 4. Verify .cpanel.yml
```bash
# Pastikan file .cpanel.yml ada di root repository
ls -la .cpanel.yml

# File ini otomatis menjalankan deployment saat pull di cPanel
```

---

## 🤖 Cara Paling Mudah (Otomatis via cPanel Git)

### Deploy ke Production (master)
1. **cPanel → Git™ Version Control**
2. Cari repository `cbtQ`
3. Klik **Update** atau **Pull**
4. ✅ Selesai! Deployment otomatis via `.cpanel.yml`

### Deploy ke Development (main)
1. **cPanel → Git™ Version Control**
2. Ganti branch ke `main`
3. Klik **Update** atau **Pull**
4. ✅ Selesai! Deployment otomatis via `.cpanel.yml`

> **Note:** `.cpanel.yml` otomatis:
> - Copy env file yang sesuai (`.env.prod` atau `.env.dev`)
> - Install dependencies & build assets
> - Run migrations
> - Set permissions

---

## 📡 Deploy Manual ke Production (master)

```bash
# 1. Pull changes
git checkout master
git pull origin master

# 2. Setup environment
cp .env.prod .env

# 3. Install & build
composer install --no-dev --optimize-autoloader
npm ci && npm run build

# 4. Migrate & cache
php artisan migrate --force
php artisan config:cache
php artisan route:cache
php artisan view:cache

# 5. Permissions
chmod -R 755 storage bootstrap/cache
```

**ATAU gunakan script:**
```bash
chmod +x deploy.sh
./deploy.sh
```

---

## 🧪 Deploy ke Development (main)

```bash
# 1. Pull changes
git checkout main
git pull origin main

# 2. Setup environment
cp .env.dev .env

# 3. Install & build
composer install --no-dev --optimize-autoloader
npm ci && npm run build

# 4. Migrate & cache
php artisan migrate --force
php artisan config:cache
php artisan route:cache
php artisan view:cache

# 5. Permissions
chmod -R 755 storage bootstrap/cache
```

---

## 🔄 Pull Request Workflow

### Method 1: GitHub CLI (Recommended)
```bash
chmod +x create-pr.sh
./create-pr.sh
```

### Method 2: Manual
```bash
# 1. Commit & push
git add .
git commit -m "Your message"
git push origin feature-branch

# 2. Create PR di GitHub
# https://github.com/YOUR_USERNAME/cbtQ/compare/main...feature-branch
```

---

## 🔥 Troubleshooting Cepat

### 500 Error
```bash
php artisan cache:clear
composer dump-autoload
```

### Assets Not Loading
```bash
npm run build
php artisan view:clear
```

### Database Error
```bash
# Cek .env
cat .env | grep DB_

# Test connection
php artisan tinker
>>> DB::connection()->getPdo();
```

---

## 📁 File Locations

```
/home/USER/public_html/cbtQ/
├── .env              # Environment config (GANTI TIAP DEPLOY)
├── .env.dev          # Development config
├── .env.prod         # Production config
├── public/
│   └── .htaccess     # Copy dari .htaccess.production
├── storage/
│   └── logs/         # Laravel logs
└── deploy.sh         # Deployment script
```

---

## ⚡ Quick Commands

```bash
# Deploy to master
git checkout master && git pull && cp .env.prod .env && composer install --no-dev && npm ci && npm run build && php artisan migrate --force && php artisan cache:clear

# Deploy to main
git checkout main && git pull && cp .env.dev .env && composer install --no-dev && npm ci && npm run build && php artisan migrate --force && php artisan cache:clear

# Create PR
./create-pr.sh
```

---

## 📞 Help

- Full guide: [DEPLOYMENT.md](./DEPLOYMENT.md)
- Laravel docs: https://laravel.com/docs
- cPanel Git: https://docs.cpanel.net/knowledge-base/web-services/guide-to-git-deployment/
