# cPanel Shared Hosting Setup Guide

## Prerequisites
- cPanel hosting with Node.js support
- Domain pointed to your hosting account
- SSH access (optional but recommended)

## Step 1: Upload Files
1. Compress your project folder to ZIP
2. Upload via cPanel File Manager to `public_html/`
3. Extract the files

## Step 2: cPanel Node.js App Setup
1. Go to **Node.js App** in cPanel
2. Click **Create Application**
3. Set these values:
   - **Node.js version**: Latest available (14+ recommended)
   - **Application mode**: Production
   - **Application root**: `public_html/commersio-project`
   - **Application URL**: Your domain
   - **Application startup file**: `app.js`

## Step 3: Environment Variables
In cPanel Node.js App, add these environment variables:
```
NODE_ENV=production
DOMAIN=yourdomain.com
FRONTEND_URL=https://yourdomain.com
BASE_URL=https://yourdomain.com
JWT_SECRET=your_jwt_secret_here
SESSION_SECRET=your_session_secret_here
MONGODB_URI=your_mongodb_connection_string
AWS_ACCESS_KEY_ID=your_aws_key
AWS_SECRET_ACCESS_KEY=your_aws_secret
AWS_REGION=your_aws_region
S3_BUCKET_NAME=your_bucket_name
```

## Step 4: Install Dependencies
1. Click **Run NPM Install** in cPanel Node.js App
2. Or via SSH: `cd public_html/commersio-project && npm install`

## Step 5: Build Frontend
1. Via SSH: `npm run build`
2. Or manually: `cd user-panel && npm install && npm run build`

## Step 6: Update Frontend API URL
Edit `user-panel/.env.production`:
```
REACT_APP_API_URL=https://yourdomain.com/api
```

## Step 7: Start Application
1. In cPanel Node.js App, click **Start App**
2. Your app will be available at your domain

## File Structure for cPanel
```
public_html/
└── commersio-project/
    ├── app.js (main entry point)
    ├── package.json
    ├── .env
    ├── config/
    ├── controllers/
    ├── models/
    ├── routes/
    ├── public/
    └── user-panel/
        └── build/ (built React app)
```

## Troubleshooting

### Common Issues:
1. **App won't start**: Check Node.js version compatibility
2. **Database connection**: Verify MongoDB URI in environment variables
3. **Frontend not loading**: Ensure `npm run build` was executed
4. **API errors**: Check domain in environment variables

### Logs:
- Check cPanel Node.js App logs
- Enable error logging in your app

### Performance:
- Use polling transport for Socket.IO (already configured)
- Optimize images and static assets
- Enable gzip compression in cPanel

## Security Notes:
- Never commit `.env` file to version control
- Use strong secrets for JWT and sessions
- Enable SSL certificate in cPanel
- Regularly update dependencies

## Support:
Contact your hosting provider if:
- Node.js is not available
- Port restrictions prevent app from running
- SSL certificate issues occur