# DEPLOYMENT GUIDE — PHP Static Site Generator (SSG) eCommerce

This architecture delivers a pure static HTML storefront served with zero database queries, combined with a secure, dynamic PHP administrative backoffice.

---

### Step 1: Upload Files to Shared Hosting / VPS
Upload the entire contents of the `/ecommerce` directory into your server's web root (e.g., `public_html` or a virtual host root `/var/www/html/ecommerce`).

```bash
# Example via rsync or FTP
rsync -avz ./ecommerce/ user@yourserver.com:/var/www/html/
```

---

### Step 2: Database Setup & Migration
1. Open cPanel / phpMyAdmin / MySQL CLI on your server.
2. Create a new database, for example: `ecommerce_ssg`.
3. Import the SQL file:
```bash
mysql -u root -p ecommerce_ssg < database/ecommerce.sql
```

---

### Step 3: Configure Database Credentials
Edit `/includes/config.php` and update:
```php
define('SITE_URL', 'https://yourdomain.com'); // Without trailing slash
define('DB_HOST', '127.0.0.1');
define('DB_NAME', 'ecommerce_ssg');
define('DB_USER', 'your_db_username');
define('DB_PASS', 'your_db_password');
```

---

### Step 4: Set Directory Permissions
Ensure PHP has write permissions to create generated static HTML files and upload media:
```bash
chmod -R 755 .
chmod -R 775 assets/uploads
chmod -R 775 products
chmod -R 775 categories
chmod -R 775 blog
```

---

### Step 5: Initial Administrator Sign-in
1. Navigate to: `https://yourdomain.com/admin`
2. Enter default credentials:
   - **Username**: `admin`
   - **Password**: `admin123`
*(Remember to update credentials under Admin Settings).*

---

### Step 6: Trigger Static Site Compilation
1. In the Admin Dashboard, click the **"Rebuild All Static Files"** button (or visit `/admin/regenerate.php`).
2. The generator will compile:
   - `index.html` (Homepage with hero, categories, featured, and testimonials)
   - `shop.html` (Full catalog with instant client-side JSON filtering)
   - `products/*.html` (Every individual product detail page)
   - `categories/*.html` (Category showcase listings)
   - `about.html`, `contact.html`
3. All static files are locked during atomic writes using `LOCK_EX`.

---

### Step 7: Verification & Performance Check
- Visit `https://yourdomain.com/` — your browser will fetch pre-compiled `index.html` directly from disk.
- Zero PHP processes run on storefront page loads.
- Client-side shopping cart persists smoothly in `localStorage`.
- Only order submissions and customer authentication hit `/api/place-order.php` and `/api/auth.php`.
