# 🚀 Panduan Deploy RH Elektronik ke Rumahweb
## Versi PHP - Full Shared Hosting

---

## ✅ Keuntungan Versi PHP

- **100% di Rumahweb** - Tidak perlu Railway/Heroku
- **Lebih Murah** - Cukup bayar hosting saja
- **Lebih Cepat** - Tidak ada latency ke server eksternal
- **Lebih Mudah** - Upload langsung via cPanel

---

## 📁 Struktur File

```
public_html/
└── rhelektronik.com/
    ├── api/                    ← Backend PHP
    │   ├── .htaccess
    │   ├── config.php
    │   ├── auth.php
    │   ├── blogs.php
    │   ├── products.php
    │   ├── services.php
    │   ├── brands.php
    │   ├── areas.php
    │   ├── contact.php
    │   ├── about.php
    │   ├── stats.php
    │   ├── upload.php
    │   └── index.php
    │
    ├── uploads/                ← Folder untuk gambar
    ├── index.html              ← Frontend React
    ├── static/
    ├── .htaccess
    └── ...
```

---

# STEP 1: Import Database via phpMyAdmin

## 1.1 Login cPanel Rumahweb
```
📍 Buka: member.rumahweb.com
📍 Login ke akun Anda
📍 Klik "cPanel"
```

## 1.2 Buat Database
```
📍 Di cPanel, cari "MySQL Databases"
📍 Buat database baru: rhey7539_website
📍 Buat user baru: rhey7539_website
📍 Password: [buat password kuat]
📍 Add user ke database dengan ALL PRIVILEGES
```

## 1.3 Import Data
```
📍 Di cPanel, klik "phpMyAdmin"
📍 Pilih database: rhey7539_website
📍 Klik tab "Import"
📍 Upload file: database.sql
📍 Klik "Go"
📍 Tunggu sampai sukses ✅
```

---

# STEP 2: Edit Konfigurasi

## 2.1 Edit api/config.php
Buka file `api/config.php` dan ubah bagian ini:

```php
// Database credentials - GANTI SESUAI CPANEL ANDA
define('DB_HOST', 'localhost');
define('DB_NAME', 'rhey7539_website');      // Nama database Anda
define('DB_USER', 'rhey7539_website');      // Username database
define('DB_PASS', 'PASSWORD_ANDA_DISINI');  // Password database

// JWT Secret - GANTI DENGAN KEY RAHASIA
define('JWT_SECRET', 'ganti-dengan-key-rahasia-anda-yang-panjang');
```

---

# STEP 3: Build Frontend

## 3.1 Install Node.js (jika belum)
```
🌐 Download: https://nodejs.org
📍 Install versi LTS
```

## 3.2 Edit Frontend .env
Buat file `frontend/.env`:
```
REACT_APP_BACKEND_URL=
PUBLIC_URL=/rhelektronik.com
```
*Kosongkan REACT_APP_BACKEND_URL karena API di domain yang sama*

## 3.3 Ganti file api.js
```
📍 Ganti file frontend/src/utils/api.js dengan frontend-api.js
```

## 3.4 Build
```bash
cd frontend
yarn install
yarn build
```

---

# STEP 4: Upload ke Rumahweb

## 4.1 Buka File Manager
```
📍 Di cPanel, klik "File Manager"
📍 Masuk ke: public_html/rhelektronik.com/
```

## 4.2 Upload Backend PHP
```
📍 Buat folder: api
📍 Upload semua file dari folder "api/" ke folder tersebut
📍 Buat folder: uploads (untuk gambar)
📍 Set permission folder uploads: 755
```

## 4.3 Upload Frontend
```
📍 Upload semua isi folder "frontend/build/" ke rhelektronik.com/
```

## 4.4 Buat .htaccess di rhelektronik.com/
```apache
<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /rhelektronik.com/

  # API requests - forward to PHP
  RewriteCond %{REQUEST_URI} ^/rhelektronik\.com/api/(.*)$
  RewriteRule ^api/(.*)$ api/index.php [QSA,L]

  # React Router - handle frontend routes
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_URI} !^/rhelektronik\.com/api/
  RewriteRule . /rhelektronik.com/index.html [L]
</IfModule>

ErrorDocument 404 /rhelektronik.com/index.html
```

---

# STEP 5: Test Website! 🎉

## 5.1 Test API
```
📍 Buka: https://rhelektronik.com/api/
📍 Harus muncul info API

📍 Buka: https://rhelektronik.com/api/services
📍 Harus muncul list services
```

## 5.2 Test Website
```
📍 Buka: https://rhelektronik.com
📍 Test semua halaman
```

## 5.3 Test Admin
```
📍 Buka: https://rhelektronik.com/admin/login
📍 Username: admin
📍 Password: admin123
```

---

# 🔧 Troubleshooting

## Error 500 pada API
```
1. Cek error log di cPanel → "Errors"
2. Pastikan credentials database benar di config.php
3. Pastikan PHP version minimal 7.4
```

## CORS Error
```
File config.php sudah handle CORS.
Jika masih error, tambahkan domain di header CORS.
```

## Upload Gambar Gagal
```
1. Pastikan folder "uploads" sudah dibuat
2. Set permission: 755
3. Pastikan PHP setting allow file upload
```

## Login Admin Gagal
```
1. Pastikan tabel "admins" ada di database
2. Coba reset password via phpMyAdmin
3. Password hash harus menggunakan PASSWORD_BCRYPT
```

---

# 📊 Estimasi Biaya

| Item | Biaya |
|------|-------|
| Hosting Rumahweb | Sudah punya |
| Domain | Sudah punya |
| Railway/Heroku | **TIDAK PERLU** |
| **TOTAL TAMBAHAN** | **Rp 0** |

---

# ✅ Checklist

- [ ] Database sudah dibuat di cPanel
- [ ] File database.sql sudah di-import
- [ ] config.php sudah diedit dengan credentials benar
- [ ] Frontend sudah di-build
- [ ] Folder api/ sudah di-upload
- [ ] Folder uploads/ sudah dibuat (permission 755)
- [ ] Frontend build sudah di-upload
- [ ] .htaccess sudah dibuat
- [ ] Test API berhasil
- [ ] Test website berhasil
- [ ] Login admin berhasil
- [ ] PASSWORD ADMIN SUDAH DIGANTI!

---

🎉 **SELAMAT! Website 100% di Rumahweb!**
