# Crescent Hospital Specialized System — cPanel & MySQL Deployment Guide

This release package is pre-configured specifically for **cPanel Hosting** using **Node.js Application** and **MySQL / MariaDB**. All Cloudflare bindings have been completely replaced with a native `mysql2` connection pool, and the database dump includes **all 833 live applications**, **66 students**, **48 certificates**, **11 departments**, and approved schedules with **zero data loss**.

---

## 📦 Package Contents
```text
CRESCENT_CPANEL_MYSQL_PACKAGE/
├── app/                              # Next.js App Router (Pages, Components & APIs)
├── lib/                              # MySQL connection pool (lib/db.ts) & adapters
├── public/                           # Logos, icons, hospital badges & Tajawal fonts
├── crescent_mysql_full_database.sql  # Complete MySQL/MariaDB database dump (UTF-8)
├── server.js                         # Production startup file for cPanel Phusion Passenger
├── package.json                      # Node.js dependencies (Next.js, React, mysql2)
├── next.config.ts                    # Next.js production configuration
├── .env                              # Preconfigured environment variables file
├── .env.example                      # Reference environment template
├── CPANEL_ADMIN_DEPLOYMENT_GUIDE.md  # This deployment guide (English)
└── دليل_التشغيل_على_cPanel.md        # This deployment guide (Arabic)
```

---

## 🚀 Step-by-Step Deployment Instructions

### Step 1: Upload Files to cPanel
1. Compress this folder into a `.zip` archive (do not include `node_modules` if you run npm install on the server).
2. Log in to your **cPanel** dashboard.
3. Open **File Manager** and navigate to your desired directory (e.g. `/home/username/crescent-app` or a directory outside `public_html`).
4. Upload the zip file and click **Extract**.

---

### Step 2: Create MySQL Database & Import Data
1. In cPanel, go to **MySQL® Database Wizard** (or **MySQL Databases**).
2. Create a new database: e.g. `crescent_db` (full name will be `cpaneluser_crescent_db`).
3. Create a new database user: e.g. `crescent_user` with a strong password.
4. Add the user to the database and check **ALL PRIVILEGES** $\rightarrow$ click **Make Changes**.
5. Return to the cPanel home page and open **phpMyAdmin**.
6. Select the newly created database on the left menu.
7. Click the **Import** tab at the top.
8. Choose the file: **`crescent_mysql_full_database.sql`**.
9. Click **Import** (or **Go**) at the bottom.
   > **Verification**: You will see 6 tables created: `applications` (833 rows), `students` (66 rows), `certificates` (48 rows), `departments` (11 rows), `schedules` (1 row), `custom_categories`.

---

### Step 3: Configure Environment Variables (`.env`)
In cPanel File Manager, edit the file named **`.env`** (ensure "Show Hidden Files" is enabled in File Manager settings):

```env
NODE_ENV=production
PORT=3000
HOSTNAME=0.0.0.0

# Database credentials created in Step 2:
DB_HOST=localhost
DB_PORT=3306
DB_USER=cpaneluser_crescent_user
DB_PASSWORD=your_actual_password_here
DB_NAME=cpaneluser_crescent_db
```
Save the file.

---

### Step 4: Configure Node.js Application in cPanel
1. In cPanel, navigate to **Software** $\rightarrow$ **Setup Node.js App**.
2. Click **Create Application**.
3. Fill in the following fields:
   - **Node.js version**: Choose **`20.x`** (or `18.x` / `22.x`).
   - **Application mode**: Select **`Production`**.
   - **Application root**: Enter the folder path where you extracted the project (e.g. `crescent-app`).
   - **Application URL**: Select the domain or subdomain (e.g. `crescent.hospital.com` or `yourdomain.com`).
   - **Application startup file**: Enter **`server.js`**.
4. Click **Create** (top right).
5. After the app is created:
   - Click the button **Run NPM Install** (or run `npm install` via SSH/Terminal).
   - In the cPanel terminal or SSH, run:
     ```bash
     npm run build
     ```
6. Click **Restart** on the Node.js application page.

---

### Step 5: Verify the Deployment
Open your website URL in the browser:
- **Main Trainee Dashboard**: `https://yourdomain.com/`
- **Admin Control Panel & Archive**: `https://yourdomain.com/admin/applications`
- **Registration & Application Forms**: `https://yourdomain.com/apply/internship`
- **ID Card Generator**: `https://yourdomain.com/idcard`
- **Experience Certificates**: `https://yourdomain.com/certificate`

---

## 🛠️ Requirements & Notes
- **PHP / Apache / Nginx**: Managed automatically by cPanel Reverse Proxy / CloudLinux Phusion Passenger.
- **Node.js**: Minimum `v18.18.0` or `v20.x` recommended.
- **MySQL / MariaDB**: MySQL 5.7+ or MariaDB 10.3+ with `JSON` and `utf8mb4` support (standard in all modern cPanel servers).
- **Max Upload / Packet Size**: To ensure seamless upload of candidate documents and photos, make sure `max_allowed_packet` in MySQL is at least `64M` (standard default on cPanel).
