# INVEETAIRE — Production Deployment Guide

This document provides complete instructions for deploying the **INVEETAIRE** platform to production environments (cPanel, Shared Hosting, VPS, or Cloud Dedicated Servers).

---

## 1. System & Server Requirements

| Component | Minimum Requirement | Recommended |
|---|---|---|
| **PHP** | `v8.1.0` or higher | `v8.2.x` |
| **Database Server** | MariaDB `v10.4+` or MySQL `v8.0+` | MariaDB `v10.11 LTS` |
| **Web Server** | Apache `v2.4+` (with `mod_rewrite` enabled) or NGINX | Apache `v2.4` + PHP-FPM |
| **Disk Space** | 500 MB base + storage for uploads | 5 GB+ |
| **Memory Limit** | `memory_limit = 128M` | `memory_limit = 256M` |

### Required PHP Extensions
Ensure the following PHP extensions are compiled and enabled in `php.ini`:
- `pdo` & `pdo_mysql` (Database PDO connectivity)
- `curl` (External HTTP requests & API checks)
- `json` (JSON request body parsing & response encoding)
- `mbstring` (Multi-byte string handling)
- `openssl` (Secure token & random byte generation)
- `fileinfo` (MIME-type verification for file uploads)

---

## 2. Directory Structure & Document Root Configuration

The web server **Document Root MUST point to the `public/` directory** of the project installation, NOT the project root directory.

### Web Server Configuration Example (Apache VirtualHost)
```apache
<VirtualHost *:443>
    ServerName app.inveetaire.com
    DocumentRoot "/home/inveetaire/public_html/public"

    <Directory "/home/inveetaire/public_html/public">
        Options -Indexes +FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>

    SSLEngine on
    SSLCertificateFile /etc/ssl/certs/inveetaire.crt
    SSLCertificateKeyFile /etc/ssl/private/inveetaire.key
</VirtualHost>
```

### Shared Hosting / cPanel Setup
1. Upload the project repository contents into a directory outside or inside your hosting user root (e.g. `/home/user/inveetaire`).
2. Point your primary domain or subdomain Document Root to `/home/user/inveetaire/public`.
3. If cPanel forces Document Root to `public_html`, move the contents of `public/` into `public_html` and adjust `ROOT_PATH` paths accordingly, or set up symbolic links.

---

## 3. Directory Permissions & Storage Folders

The following storage directories must exist and be writable by the web server user (`www-data`, `apache`, or cPanel user account):

```bash
# Required writable directories (chmod 775 or 755 depending on host group rules)
storage/
├── cache/
├── developer/
├── exports/
├── logs/
├── reports/
├── sessions/
└── uploads/
```

### Permission Commands
```bash
chmod -R 775 storage/
# If using Apache/Nginx user ownership:
chown -R www-data:www-data storage/
```

> [!IMPORTANT]
> The `storage/` directory is protected by `storage/.htaccess` to prevent direct web browsing of logs, session tokens, or exported spreadsheets.

---

## 4. Database Setup & Initialization

1. Create a MySQL database (e.g. `inveetaire_prod`).
2. Create a dedicated database user with `SELECT`, `INSERT`, `UPDATE`, `DELETE` privileges.
3. Import the canonical schema into MariaDB/MySQL:
   ```bash
   mysql -u inveetaire_user -p inveetaire_prod < database/schema.sql
   ```
4. Optionally import initial commercial plan seed data:
   ```bash
   mysql -u inveetaire_user -p inveetaire_prod < database/seed.sql
   ```

---

## 5. Environment Configuration (.env)

Copy `.env.example` to `.env` in the root directory:
```bash
cp .env.example .env
```

### Production `.env` Required Settings Checklist
```ini
# Application Setup
APP_NAME=INVEETAIRE
APP_ENV=production
APP_DEBUG=false
APP_URL=https://app.inveetaire.com

# SECURITY RULE: Must be false in production
DEVELOPER_MODE=false

# Database Configuration
DB_HOST=127.0.0.1
DB_PORT=3306
DB_NAME=inveetaire_prod
DB_USER=inveetaire_app
DB_PASS=YourSuperSecretPasswordHere
DB_CHARSET=utf8mb4

# Session Security & Timeouts (in seconds)
SESSION_NAME=inveetaire_session
SESSION_TIMEOUT_ADMIN=28800
SESSION_TIMEOUT_COUPLE=86400
SESSION_TIMEOUT_CREW=43200
SESSION_INACTIVITY_TIMEOUT=7200
```

---

## 6. Pre-Flight Deployment Checklist

- [ ] **SSL / HTTPS Configured**: Verify site loads over `https://` with valid SSL certificate.
- [ ] **`APP_ENV=production`**: Confirmed in `.env`.
- [ ] **`APP_DEBUG=false`**: Confirmed in `.env` (prevents PHP stack trace exposure).
- [ ] **`DEVELOPER_MODE=false`**: Confirmed in `.env` (disables `/app/developer/*` console).
- [ ] **Database Connection Verified**: Database tables imported and accessible.
- [ ] **Storage Permissions Verified**: `storage/sessions/`, `storage/logs/`, `storage/uploads/` writable.
- [ ] **Security Cookies Verified**: Session cookie flags set to `HttpOnly`, `SameSite=Strict`, `Secure=true`.
- [ ] **PHP Error Logging Checked**: Errors written to `storage/logs/app.log`, display_errors turned OFF in production `php.ini`.

---

*Document Version: 1.0.0 — Post-RC001 Release Candidate*
