## cPanel Deployment Steps for Trust Tax Advisor

### Prerequisites
- cPanel with Node.js support (Passenger)
- MySQL database access
- SSH access (recommended)
- Domain name: crm.trusttaxadvisor.com

### Deployment Steps

#### 1. Upload Project Files
```bash
# Via FTP/SFTP or cPanel File Manager
- Upload all project files to public_html or subdirectory
- Ensure backend/ and frontend/ are at the correct locations
```

#### 2. Configure Database
```bash
# Via cPanel MySQL Databases
- Create a new MySQL database: fmpdcrei_tta1
- Create a user: fmpdcrei_tta1 with password: Chintan@1993
- Import the schema.sql file:
  - phpMyAdmin → Import → Select database/schema.sql → Import
```

#### 3. Environment Configuration
```bash
cd backend
# For development
cp .env.example .env

# Edit .env with your actual values:
nano .env
```

#### 4. Install Dependencies
```bash
cd backend
npm install --production

cd ../frontend
npm install
npm run build
```

#### 5. Create Passenger App
```bash
# In cPanel:
1. Go to: Setup Node.js App
2. Configure:
   - Application root: /public_html
   - Application startup file: backend/server.js
   - Node.js version: Latest LTS available
3. Create app

# Or manually place startup.sh and .htaccess in root
```

#### 6. Point Domain
- In cPanel, ensure your domain points to the public_html directory
- Update DNS if needed

#### 7. Run Database Setup
```bash
mysql -u username -p trust_tax_advisor < database/schema.sql
```

#### 8. Verify Installation
- Visit: http://thechintanpatel.co.in/api/health
- Should return: `{ "status": "ok", "timestamp": "..." }`

### Environment Variables (Updated .env)
```
DB_HOST=localhost
DB_USER=fmpdcrei_tta1
DB_PASSWORD=fmpdcrei_tta1
DB_NAME=fmpdcrei_tta1

JWT_SECRET=your_random_secret_key_here

SMTP_USER=noreply@trusttaxadvisor.com
SMTP_PASSWORD=Chintan@1993
SMTP_HOST=mail.trusttaxadvisor.com
SMTP_PORT=465

WHATSAPP_API_URL=https://whatsapp.thechintanpatel.co.in/api/create-message
WHATSAPP_APP_KEY=1a68fcd1-3746-4be7-9cc0-334423e4e1d5
WHATSAPP_AUTH_KEY=yoQ5tAx2MjtnOM2JCu8HU5IuL14DDkKesmGnCVOLRzuyVbu1qv

PORT=3000
NODE_ENV=production
CORS_ORIGIN=http://thechintanpatel.co.in
```

### Troubleshooting

**Port Already in Use**
- Change PORT in .env to an available port
- Passenger will handle the rest

**Database Connection Failed**
- Verify MySQL user has remote access
- Check DB credentials in .env
- Ensure database exists

**Node Modules Missing**
```bash
cd backend
rm -rf node_modules package-lock.json
npm install --production
```

**Static Files Not Serving**
- Rebuild frontend: `npm run build`
- Ensure dist files are copied to backend/public

### Production Optimization

**Enable Caching**
```bash
# .htaccess
<IfModule mod_expires.c>
  ExpiresActive On
  ExpiresByType text/css "access plus 1 month"
  ExpiresByType application/javascript "access plus 1 month"
  ExpiresByType image/jpeg "access plus 1 year"
  ExpiresByType image/png "access plus 1 year"
</IfModule>
```

**SSL/HTTPS**
- Use cPanel AutoSSL or purchase SSL certificate
- Redirect HTTP to HTTPS in .htaccess

**Rate Limiting**
- Already configured in backend (see express-rate-limit)
- Adjust limits in server.js if needed

### Backup & Maintenance

**Database Backup**
```bash
mysqldump -u fmpdcrei_tta1 -p fmpdcrei_tta1 > backup_$(date +%Y%m%d).sql
```

**Log Monitoring**
```bash
# Check cPanel error logs
tail -f /var/log/cpanel/error_log
```

### Support & Updates
- Check backend package.json for dependencies
- Keep Node.js and npm updated via cPanel
- Monitor disk space and database size
