# 🚀 PANDUAN DEPLOYMENT - MSJ Guidelines

## ⚠️ PENTING: Masalah URL Double (msjguidelines/msjguidelines)

Jika Anda mengalami masalah URL menjadi double seperti `https://devxampp8.spunindo.com/msjguidelines/msjguidelines/visual-component`, ikuti langkah-langkah berikut:

### 📝 Langkah Perbaikan:

#### 1. **Update File .env di Server Production**

Pastikan `APP_URL` di file `.env` server production sudah benar:

```env
APP_URL=https://devxampp8.spunindo.com/msjguidelines
```

**BUKAN:**
```env
APP_URL=http://localhost  ❌
APP_URL=https://devxampp8.spunindo.com  ❌ (tanpa subfolder)
```

#### 2. **Clear Cache di Server**

Jalankan command berikut di server production:

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

#### 3. **Restart Web Server**

Restart Apache/Nginx untuk memastikan semua perubahan diterapkan:

```bash
# Untuk Apache
sudo systemctl restart apache2

# Atau jika menggunakan service httpd
sudo systemctl restart httpd
```

---

## 🔧 Konfigurasi Laravel untuk Subfolder

### File yang Sudah Diperbaiki:

✅ **resources/views/layouts/navbars/guest/topnav.blade.php**
   - Fungsi `toggleLanguage()` sudah diperbaiki untuk menghapus base path sebelum redirect
   - Mencegah URL double ketika ganti bahasa

✅ **routes/web.php**
   - Route language sudah menggunakan `redirect()->back()` dan custom redirect URL
   - Support untuk subfolder deployment

✅ **config/cors.php**
   - CORS sudah dikonfigurasi untuk mendukung image-proxy Photopea

---

## 📋 Checklist Deployment Production

### Pre-Deployment:

- [ ] Update `.env` dengan APP_URL yang benar (termasuk subfolder)
- [ ] Set `APP_ENV=production`
- [ ] Set `APP_DEBUG=false`
- [ ] Update database credentials
- [ ] Generate APP_KEY baru jika diperlukan: `php artisan key:generate`

### Upload Files:

- [ ] Upload semua file project ke server
- [ ] Pastikan folder `storage` dan `bootstrap/cache` writable (777 atau 775)
- [ ] Create symlink untuk storage: `php artisan storage:link`

### After Upload:

```bash
# 1. Install dependencies (jika ada composer.lock)
composer install --optimize-autoloader --no-dev

# 2. Clear all cache
php artisan config:clear
php artisan cache:clear
php artisan route:clear
php artisan view:clear

# 3. Optimize untuk production
php artisan config:cache
php artisan route:cache
php artisan view:cache

# 4. Create storage symlink
php artisan storage:link

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

### Configure Web Server:

#### Apache (.htaccess sudah ada di folder public)

Pastikan DocumentRoot mengarah ke folder `public`:
```apache
DocumentRoot /path/to/msjguidelines/public
```

Atau jika di subfolder:
```apache
Alias /msjguidelines /path/to/msjguidelines/public
<Directory /path/to/msjguidelines/public>
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>
```

---

## 🐛 Troubleshooting

### URL Masih Double?

1. **Cek APP_URL di .env:**
   ```bash
   cat .env | grep APP_URL
   ```
   Harus: `APP_URL=https://devxampp8.spunindo.com/msjguidelines`

2. **Clear cache lagi:**
   ```bash
   php artisan config:clear
   php artisan config:cache
   ```

3. **Clear browser cache:**
   - Tekan Ctrl+Shift+Delete
   - Clear cache dan cookies untuk domain tersebut

### Gambar Photopea Tidak Muncul?

1. **Cek route image-proxy:**
   ```bash
   php artisan route:list | grep image-proxy
   ```

2. **Test akses image-proxy:**
   Buka: `https://devxampp8.spunindo.com/msjguidelines/image-proxy?path=storage/uploads/test.png`

3. **Cek CORS headers:**
   - Buka Developer Tools (F12)
   - Tab Network
   - Cek response headers harus ada `Access-Control-Allow-Origin: *`

### Error 404 atau 500?

1. **Cek Apache error log:**
   ```bash
   tail -f /var/log/apache2/error.log
   ```

2. **Cek Laravel log:**
   ```bash
   tail -f storage/logs/laravel.log
   ```

3. **Set temporary debug:**
   ```env
   APP_DEBUG=true
   ```
   Lalu clear cache dan lihat error detailnya

---

## 📞 Support

Jika masih ada masalah:

1. Screenshot error yang muncul
2. Copy isi file `.env` (sensor password/key)
3. Copy error dari `storage/logs/laravel.log`
4. Hubungi developer

---

## ✅ Verifikasi Deployment Berhasil

Cek halaman berikut di browser:

- [ ] Homepage: `https://devxampp8.spunindo.com/msjguidelines/`
- [ ] Login: `https://devxampp8.spunindo.com/msjguidelines/login`
- [ ] Brand: `https://devxampp8.spunindo.com/msjguidelines/brand`
- [ ] Document: `https://devxampp8.spunindo.com/msjguidelines/document`
- [ ] Typography: `https://devxampp8.spunindo.com/msjguidelines/typography`
- [ ] Mockup: `https://devxampp8.spunindo.com/msjguidelines/mockup`
- [ ] Visual Component: `https://devxampp8.spunindo.com/msjguidelines/visual-component`

Test fitur:
- [ ] Ganti bahasa (EN/ID) - URL tidak double ✓
- [ ] Download file - bisa download ✓
- [ ] Buka Photopea - gambar muncul ✓
- [ ] Search - hasil muncul ✓

---

## 🎉 Deployment Selesai!

Jika semua checklist di atas sudah ✅, deployment sukses!
