# Panduan Instalasi Laravel
## Sistem Informasi Manajemen SDM Puskesmas Muara Kumpeh

## Persyaratan

1. **PHP** 8.2 atau lebih tinggi (Laravel 12 membutuhkan PHP 8.2+)
2. **Composer** (sudah terinstall)
3. **MySQL/MariaDB** (via XAMPP)
4. **Extension PHP**:
   - OpenSSL
   - PDO
   - Mbstring
   - Tokenizer
   - XML
   - Ctype
   - JSON
   - BCMath

## Langkah Instalasi

### 1. Install Dependencies

```bash
composer install
```

### 2. Setup Environment

Copy file `.env.example` menjadi `.env`:

```bash
copy .env.example .env
```

Atau di PowerShell:
```powershell
Copy-Item .env.example .env
```

### 3. Generate Application Key

```bash
php artisan key:generate
```

### 4. Konfigurasi Database

Edit file `.env` dan sesuaikan konfigurasi database:

```env
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=sdm_puskesmas_muara_kumpeh
DB_USERNAME=root
DB_PASSWORD=
```

### 5. Import Database

Pastikan database sudah diimport menggunakan file `database/schema.sql` (lihat `database/INSTALL.md`).

### 6. Setup Storage Link (jika diperlukan)

```bash
php artisan storage:link
```

### 7. Jalankan Aplikasi

**Opsi 1: Menggunakan PHP Built-in Server**

```bash
php artisan serve
```

Akses aplikasi di: `http://localhost:8000`

**Opsi 2: Menggunakan XAMPP**

1. Pastikan Apache berjalan di XAMPP
2. Akses aplikasi di: `http://localhost/sdm_manajemen_puskes/public`

**Opsi 3: Setup Virtual Host (Recommended untuk Production)**

Edit file `C:\xampp\apache\conf\extra\httpd-vhosts.conf`:

```apache
<VirtualHost *:80>
    ServerName sdm-puskesmas.test
    DocumentRoot "C:/xampp/htdocs/sdm_manajemen_puskes/public"
    <Directory "C:/xampp/htdocs/sdm_manajemen_puskes/public">
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>
```

Edit file `C:\Windows\System32\drivers\etc\hosts`:

```
127.0.0.1    sdm-puskesmas.test
```

Restart Apache, lalu akses: `http://sdm-puskesmas.test`

## Default Login

- **Username**: `admin`
- **Password**: `admin123`

⚠️ **PENTING**: Ganti password default setelah instalasi!

## Troubleshooting

### Error: "Class 'PDO' not found"
**Solusi**: Aktifkan extension PDO di `php.ini`:
```ini
extension=pdo_mysql
```

### Error: "No application encryption key"
**Solusi**: Jalankan `php artisan key:generate`

### Error: "SQLSTATE[HY000] [1045] Access denied"
**Solusi**: Periksa konfigurasi database di `.env`

### Error: "The stream or file could not be opened"
**Solusi**: Pastikan folder `storage` dan `bootstrap/cache` dapat ditulis (writable)

### Error: "Route [login] not defined"
**Solusi**: Pastikan semua route sudah terdaftar di `routes/web.php`

## Development Commands

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

# Optimize
php artisan optimize

# Run migrations (jika menggunakan migrations)
php artisan migrate

# Run seeders (jika menggunakan seeders)
php artisan db:seed
```

## Security Checklist

- [x] Password hashing (bcrypt)
- [x] Role-based access control
- [x] Session management
- [x] Audit logging
- [x] CSRF protection
- [x] XSS protection
- [x] SQL injection prevention (Eloquent ORM)
- [x] Security headers
- [ ] HTTPS (untuk production)
- [ ] Rate limiting (dapat ditambahkan)

## Next Steps

1. Ganti password default admin
2. Setup email untuk notifications (jika diperlukan)
3. Konfigurasi backup database otomatis
4. Setup monitoring dan logging
5. Deploy ke production server

## Support

Untuk pertanyaan atau masalah, lihat dokumentasi:
- Database: `database/README.md`
- Security: `database/SECURITY_FEATURES.md`
- Installation: `database/INSTALL.md`

