# Panduan Deploy ke Shared Hosting

> **Panduan lengkap** mengupload website ke shared hosting (cPanel, Plesk, dll).
> Untuk hosting murah seperti Niagahoster, Domainesia, IDCloudHost, dll.

<div align="center">

**Mulai Digital** — *Solusi Website untuk Pertumbuhan Bisnis Anda*

</div>

---

## Daftar Isi

1. [Sebelum Memulai](#1-sebelum-memulai)
2. [Persiapan di Lokal](#2-persiapan-di-lokal)
3. [Upload ke Hosting](#3-upload-ke-hosting)
4. [Konfigurasi di Hosting](#4-konfigurasi-di-hosting)
5. [Setup Database](#5-setup-database)
6. [Finalisasi](#6-finalisasi)
7. [Troubleshooting](#7-troubleshooting)

---

## 1. Sebelum Memulai

### Yang Anda Butuhkan

| Item | Keterangan |
|------|------------|
| **Akun Hosting** | Shared hosting dengan PHP 8.4+ dan MySQL 8.2+ |
| **Panel Hosting** | cPanel, Plesk, atau sejenisnya |
| **File Manager** | Untuk upload file (atau FTP) |
| **Database** | Sudah dibuat di panel hosting |

### Persyaratan Hosting

Pastikan hosting Anda mendukung:
- PHP 8.4 atau lebih baru
- MySQL 8.2+ atau MariaDB 10.4+
- Extension PHP: mbstring, xml, ctype, json, bcmath, gd, zip
- mod_rewrite (untuk Apache)

---

## 2. Persiapan di Lokal

Sebelum upload, **build aset di komputer Anda**:

### 2.1 Build Aset Frontend

```bash
npm run build
```

Output:
```
 built in 30.00s
```

### 2.2 Cache Konfigurasi

```bash
php artisan config:cache
php artisan route:cache
php artisan view:cache
```

### 2.3 Kompres File

1. Buka file manager (Explorer/Finder)
2. Pilih **SEMUA file** di folder project (kecuali `node_modules`, `.git`, `tests`)
3. Klik kanan → **Compress** → **ZIP**
4. Namakan file: `website-mulai-digital.zip`

> **Penting:** Jangan upload folder `node_modules`, `.git`, atau `tests`!

---

## 3. Upload ke Hosting

### 3.1 Buka File Manager

1. Login ke **cPanel** hosting Anda
2. Klik **File Manager**
3. Masuk ke folder `public_html` (atau subdomain folder)

### 3.2 Upload File ZIP

1. Klik **Upload** (di toolbar atas)
2. Pilih file `website-mulai-digital.zip`
3. Tunggu hingga upload selesai
4. Klik **Go Back**

### 3.3 Ekstrak File

1. Klik kanan file `website-mulai-digital.zip`
2. Pilih **Extract**
3. Pilih folder: `/public_html/` (atau subdomain folder Anda)
4. Klik **Extract Files**

### 3.4 Pindahkan File (Jika di Subfolder)

Jika Anda menggunakan subfolder (misal: `/public_html/website/`):

1. Buka folder hasil ekstrak
2. Pilih **semua file** di dalamnya
3. Klik **Move**
4. Masukkan path: `/public_html/` (atau `/public_html/website/`)
5. Klik **Move File**

### 3.5 Hapus File ZIP

Setelah ekstrak, **hapus file ZIP** untuk menghemat space:
1. Klik kanan `website-mulai-digital.zip`
2. Pilih **Delete**

---

## 4. Konfigurasi di Hosting

### 4.1 Edit File .env

1. Buka **File Manager**
2. Cari file `.env` di root folder
3. Klik kanan → **Edit**
4. Ubah konfigurasi berikut:

```env
APP_NAME="Mulai Digital"
APP_ENV=production
APP_DEBUG=false
APP_URL=https://website-anda.com

DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=nama_database_anda
DB_USERNAME=nama_user_database
DB_PASSWORD=password_database

SESSION_DRIVER=database
CACHE_STORE=database
QUEUE_CONNECTION=database
```

> **Penting:**
> - `APP_URL` = URL website Anda (https://website-anda.com)
> - `DB_*` = Konfigurasi database hosting Anda
> - `APP_DEBUG=false` untuk production!

### 4.2 Buat Storage Link

Jika hosting mendukung SSH:
```bash
php artisan storage:link
```

Jika **tidak ada SSH**, buat manual:
1. Buka **File Manager**
2. Buat folder baru: `storage/app/public`
3. Copy semua file dari `storage/app/public` ke `public/storage`

---

## 5. Setup Database

### 5.1 Buat Database di Hosting

1. Login ke **cPanel**
2. Klik **MySQL Databases**
3. Buat database baru:
   - Nama: `mulai_digital` (atau sesuai keinginan)
   - Klik **Create Database**

### 5.2 Buat User Database

1. Di bagian **MySQL Users**, buat user baru:
   - Username: `user_mulai` (atau sesuai keinginan)
   - Password: (buat password yang kuat)
   - Klik **Create User**

### 5.3 Tambah User ke Database

1. Di bagian **Add User to Database**
2. Pilih user dan database yang baru dibuat
3. Klik **Add**
4. Centang **ALL PRIVILEGES**
5. Klik **Make Changes**

### 5.4 Import Database

#### Menggunakan phpMyAdmin

1. Buka **phpMyAdmin** dari cPanel
2. Pilih database yang baru dibuat
3. Klik tab **Import**
4. Klik **Choose File**
5. Pilih file database (`.sql`) dari folder project
6. Klik **Go** / **Import**

>  **Tips:** Jika tidak ada file `.sql`, jalankan migrasi via SSH:
> ```bash
> php artisan migrate --seed
> ```

---

## 6. Finalisasi

### 6.1 Jalankan Migrasi (Jika Ada SSH)

```bash
cd /path/to/public_html
php artisan migrate --force
php artisan db:seed --force
```

### 6.2 Set Permission (Jika Ada SSH)

```bash
chmod -R 755 storage bootstrap/cache
chown -R www-data:www-data storage bootstrap/cache
```

### 6.3 Buat .htaccess

Jika website tidak bisa diakses, buat file `.htaccess` di root:

```apache
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
```

### 6.4 Akses Website

Buka browser dan akses:
```
https://website-anda.com
```

### 6.5 Login Admin

```
https://website-anda.com/login
```

**Akun Default:**
| Field | Nilai |
|-------|-------|
| **Email** | admin@example.com |
| **Password** | admin@example.com |

---

## 7. Troubleshooting

### Website Error 500

**Penyebab:** Konfigurasi salah atau permission kurang

**Solusi:**
1. Cek file `.env` — pastikan semua konfigurasi benar
2. Cek log error di `storage/logs/laravel.log`
3. Set permission:
   ```bash
   chmod -R 755 storage bootstrap/cache
   ```

### Website Blank Hitam/Putih

**Penyebab:** Aset frontend belum di-build

**Solusi:**
1. Build ulang di lokal: `npm run build`
2. Upload folder `public/build` ke hosting

### Error "No application encryption key"

**Penyebab:** Key belum di-generate

**Solusi:**
```bash
php artisan key:generate
```

### Error "SQLSTATE Connection refused"

**Penyebab:** Database belum siap atau konfigurasi salah

**Solusi:**
1. Pastikan database sudah dibuat
2. Cek `DB_*` di file `.env`
3. Pastikan user database punya akses ke database

### Error "Storage link not found"

**Penyebab:** Link storage belum dibuat

**Solusi:**
```bash
php artisan storage:link
```

Atau buat manual di File Manager (lihat Langkah 4.2)

### CSS/JS Tidak Muncul

**Penyebab:** Aset frontend belum di-build atau path salah

**Solusi:**
1. Pastikan folder `public/build` ada
2. Jika tidak ada, build di lokal: `npm run build`
3. Upload folder `public/build` ke hosting

### URL Tidak Bisa Diakses

**Penyebab:** mod_rewrite belum aktif

**Solusi:**
1. Hubungi support hosting untuk mengaktifkan mod_rewrite
2. Atau buat file `.htaccess` (lihat Langkah 6.3)

---

## Butuh Bantuan?

Jika mengalami kendala, hubungi kami:

- **Email:** [mulaidigitalofficial@gmail.com](mailto:mulaidigitalofficial@gmail.com)
- **Website:** [mulaidigital.com](https://mulaidigital.com)

---

Terima kasih telah membeli source code dari Mulai Digital.
