# cPanel Deployment Guide (No Git)

This guide explains how to deploy the Digital Services Panel to cPanel using only the file manager.

---

## Prerequisites

- cPanel account with Node.js support OR PHP with Laravel support
- cPanel MySQL/MariaDB database
- SSH/Terminal access (optional, recommended)
- FTP or cPanel File Manager

---

## Step 1: Prepare Files Locally

On your local machine (Windows), prepare the project:

```bash
cd c:\Users\Ibraheem\Projects\digital-services-panel

# Build the frontend
npm install --prefix client
npm run build --prefix client

# This creates client/dist folder with all static files
```

---

## Step 2: Create Database in cPanel

1. Log in to **cPanel**
2. Go to **MySQL Databases** (or **Databases**)
3. Create a new database:
   - Database name: `your_username_dbname`
   - Add a new MySQL user with a strong password
4. Grant all privileges to the user for this database

---

## Step 3: Upload Project Files via cPanel File Manager

1. In cPanel, open **File Manager**
2. Navigate to your app root (e.g., `public_html/` for frontend-only, or a custom Node app folder)
3. Upload the following folders:
   - `server/` (backend code)
   - `client/dist/` (built frontend static files)
   - Root level files:
     - `package.json`
     - `.env` (configure with your cPanel DB credentials)
     - `README.md`

### File structure on cPanel:

```
your_app_root/
├── server/
│   ├── index.js
│   ├── package.json
│   ├── routes/
│   │   └── *.js
│   ├── middleware/
│   ├── utils/
│   └── scripts/
├── client/
│   └── dist/
│       ├── index.html
│       ├── assets/
│       └── ...
├── package.json
└── .env (DO NOT share this file)
```

---

## Step 4: Configure `.env` File

In cPanel File Manager, create or edit `.env` file with your cPanel database credentials:

```dotenv
# Laravel Core
APP_NAME="Digital Services Panel"
APP_ENV=production
APP_KEY=base64:YOUR_KEY_HERE
APP_DEBUG=false
APP_URL=https://yourdomain.com

# cPanel Database
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=your_cpanel_database_name
DB_USERNAME=your_cpanel_db_user
DB_PASSWORD=your_cpanel_db_password
DB_CHARSET=utf8mb4
DB_COLLATION=utf8mb4_unicode_ci

# Admin Credentials
ADMIN_EMAIL=admin@example.com
ADMIN_PASSWORD_HASH=your_bcrypt_hash
# OR (dev only):
# ADMIN_PASSWORD=plain_password

# JWT
JWT_SECRET=your_long_random_secret_here

# URLs
CLIENT_URL=https://yourdomain.com
FRONTEND_URL=https://yourdomain.com

# Integrations (leave blank if not using)
WHMCS_URL=
WHMCS_IDENTIFIER=
WHMCS_SECRET=
GOOGLE_CLIENT_ID=
GOOGLE_CLIENT_SECRET=
GEMINI_API_KEY=
```

> **⚠️ Important:** Never upload `.env` to public repositories. Keep it private to cPanel only.

---

## Step 5: Install Dependencies via SSH

If cPanel supports Node.js, use SSH to install dependencies:

```bash
ssh user@yourdomain.com

cd path/to/your/app

# Install server dependencies
npm install --prefix server

# Install frontend dependencies (optional, already built)
npm install --prefix client
```

---

## Step 6: Create Database Tables

Use cPanel **phpMyAdmin** to run the database schema:

1. Log in to **phpMyAdmin**
2. Select your database
3. Go to **SQL** tab
4. Paste the content from `supabase/schema.sql` (or your Laravel migration SQL)
5. Click **Go** to execute

### OR use Laravel migrations (if you convert to full Laravel):

```bash
php artisan migrate
```

---

## Step 7: Start the App

### Option A: Node.js App on cPanel

If cPanel supports Node.js apps:
1. In cPanel, go to **Node.js Selector** or **Setup Node.js App**
2. Create new app:
   - Application root: `/path/to/your/app`
   - Application URL: `yourdomain.com`
   - Application startup file: `server/index.js`
   - Node.js version: 18+
3. Click **Save**

### Option B: PHP/Laravel on cPanel

If only PHP is supported:
- Move `client/dist/*` to cPanel `public_html/`
- Use Laravel with PHP-FPM
- Route all API calls to your separate Node backend (hosted elsewhere) OR convert backend to PHP

---

## Step 8: Verify Deployment

1. Visit `https://yourdomain.com`
2. You should see your dashboard frontend
3. Try logging in to test `/api/auth/login` endpoint
4. Check cPanel **Error Logs** if issues occur

---

## Updating Files Later

To update without Git:

1. **Use cPanel File Manager**:
   - Edit files directly in File Manager's code editor
   - OR delete old files and upload new versions

2. **For code changes**:
   - Modify files locally
   - Rebuild frontend: `npm run build --prefix client`
   - Upload updated `client/dist/` and modified backend files via File Manager

3. **Restart the app** (if using Node.js app in cPanel):
   - cPanel → Node.js Apps → Restart your app

---

## Troubleshooting

### API returns 404
- Check that server routes are correctly configured in `server/routes/*.js`
- Verify cPanel app startup file is `server/index.js`
- Check `.env` settings for `CLIENT_URL` and `FRONTEND_URL`

### Database connection error
- Verify `DB_HOST`, `DB_USER`, `DB_PASSWORD`, `DB_DATABASE` in `.env`
- Check that MySQL user has proper privileges in cPanel **MySQL Users**
- Confirm database tables exist (check phpMyAdmin)

### Static files not loading
- Ensure `client/dist/` is uploaded to correct path
- Check cPanel file permissions (should be 755 for folders, 644 for files)

### 2FA or admin login not working
- Ensure database tables are created (run schema.sql in phpMyAdmin)
- Check `ADMIN_EMAIL` and `ADMIN_PASSWORD_HASH` in `.env`

---

## Security Notes

- **Never commit `.env` to Git** — keep it private on cPanel only
- **Change default passwords** for admin account
- **Use HTTPS only** — configure SSL in cPanel
- **Keep dependencies updated** — periodically run `npm install` to get security patches
- **Backup your database** regularly via cPanel **Backup**

---

## Useful cPanel Paths

- **File Manager**: `yourdomain.com:2083/` → Files tab
- **phpMyAdmin**: `yourdomain.com:2083/` → Databases → phpMyAdmin
- **MySQL Databases**: `yourdomain.com:2083/` → Databases → MySQL Databases
- **Node.js Apps** (if available): `yourdomain.com:2083/` → Node.js Apps
- **Error Logs**: `yourdomain.com:2083/` → Logs

---

For questions or issues, refer to your cPanel provider's support documentation.
