# 🚀 DocuTrack Deployment Guide
## Domain: hr.gsolutions.com.kw | cPanel Hosting

---

## PART 1 — Build the React Frontend (on YOUR computer)

> Do this on Windows/Mac before uploading anything.
> You only need Node.js installed. Download from nodejs.org if you don't have it.

```bash
# 1. Open terminal / command prompt
# 2. Go into the frontend folder
cd frontend

# 3. Install dependencies (one time only)
npm install

# 4. Build for production
npm run build
```

This creates a `dist/` folder — those are your static files to upload.

---

## PART 2 — Set Up Subdomain in cPanel

1. Login to **cPanel**
2. Go to **Domains → Subdomains** (or **Addon Domains**)
3. Create subdomain:
   - Subdomain: `hr`
   - Domain: `gsolutions.com.kw`
   - Document Root: `/home/USERNAME/hr.gsolutions.com.kw`
4. Click **Create**

---

## PART 3 — Upload Backend (Laravel)

1. Go to **cPanel → File Manager**
2. Navigate to `/home/USERNAME/hr.gsolutions.com.kw/`
3. Upload `docutrack-backend.zip` → Extract it here
4. You should see these folders: `app/`, `database/`, `public/`, `routes/`, etc.
5. **Rename** `root.htaccess` → `.htaccess` (in the root, not inside public/)

Your folder structure should look like:
```
/home/USERNAME/hr.gsolutions.com.kw/
├── .htaccess          ← renamed from root.htaccess
├── app/
├── bootstrap/
├── config/
├── database/
├── public/            ← Laravel's web root
│   ├── .htaccess
│   └── index.php
├── routes/
├── storage/
├── .env
└── install.sh
```

---

## PART 4 — Upload Frontend (React dist/)

1. In File Manager, go to `/home/USERNAME/hr.gsolutions.com.kw/public/`
2. Upload the **contents** of your `dist/` folder into `public/`
   (so `index.html` sits at `public/index.html`)

---

## PART 5 — Create Database

1. Go to **cPanel → MySQL Databases**
2. **Create Database**: e.g. `gsol_docutrack`
3. **Create User**: e.g. `gsol_docuuser` + strong password
4. **Add User to Database** → select All Privileges → click Add
5. Note down: database name, username, password

---

## PART 6 — Run the Installer (Terminal)

1. Go to **cPanel → Terminal**
2. Run:

```bash
cd ~/hr.gsolutions.com.kw
bash install.sh
```

3. It will ask for:
   - Database name, user, password (from Part 5)
   - Admin name, email, password (your login to the app)

4. That's it! ✓

---

## PART 7 — Point Subdomain to public/ folder

cPanel needs to serve from the `public/` subfolder, not the root.

**Option A — Change Document Root (easiest):**
1. Go to **cPanel → Domains**
2. Find `hr.gsolutions.com.kw`
3. Edit Document Root → set to: `hr.gsolutions.com.kw/public`
4. Save

**Option B — Use .htaccess (already done):**
The `root.htaccess` (rename to `.htaccess`) in your root folder
automatically redirects all traffic to `public/`.

---

## PART 8 — Enable SSL (HTTPS)

1. Go to **cPanel → SSL/TLS** or **Let's Encrypt**
2. Issue a free SSL for `hr.gsolutions.com.kw`
3. Wait 2-5 minutes, then visit https://hr.gsolutions.com.kw

---

## ✅ Done!

Visit **https://hr.gsolutions.com.kw** and login with your admin credentials.

---

## Troubleshooting

| Problem | Fix |
|---------|-----|
| 500 Error | Check `storage/logs/laravel.log` via File Manager |
| White page | Make sure Document Root points to `public/` |
| Login fails | Check DB credentials in `.env` |
| CORS error | Check `config/cors.php` has your domain |
| File upload fails | Run `chmod -R 775 storage` in Terminal |

---

## Cron Job (auto-update document statuses)

In cPanel → **Cron Jobs**, add:
```
* * * * * php /home/USERNAME/hr.gsolutions.com.kw/artisan schedule:run >> /dev/null 2>&1
```
Replace `USERNAME` with your actual cPanel username.
