# Comarnet Website - Deployment Package

This package contains everything needed to deploy the Comarnet website on your cPanel server.

## 📦 Package Contents

```
comarnet-modern/
├── dist/                          # Production build files
│   ├── public/                    # Frontend (HTML, CSS, JS)
│   └── index.js                   # Backend server
├── package.json                   # Node.js dependencies
├── pnpm-lock.yaml                 # Dependency lock file
├── DEPLOYMENT_GUIDE.md            # Complete step-by-step guide
├── DEPLOYMENT_README.md           # This file
├── .env.production.example        # Environment template
├── DATABASE_SETUP.sql             # Database initialization script
└── deploy.sh                      # Automated deployment script
```

## 🚀 Quick Start (5 Minutes)

### 1. Upload to cPanel

```bash
# Via SFTP or Git clone
# Upload to: public_html/comarnet-app/
```

### 2. Configure Database

```bash
# In cPanel, create MySQL database:
# - Database: comarnet_prod
# - User: comarnet_user
# - Password: [your-strong-password]
```

### 3. Set Environment Variables

```bash
# SSH into your server
ssh username@comarnet.com

# Navigate to app directory
cd public_html/comarnet-app

# Create .env.production
cp .env.production.example .env.production

# Edit with your database credentials
nano .env.production
```

### 4. Run Deployment Script

```bash
# Make script executable
chmod +x deploy.sh

# Run deployment
./deploy.sh
```

### 5. Configure in cPanel

1. Go to **Setup Node.js App**
2. Click **Create Application**
3. Fill in:
   - **Application root**: `/home/username/public_html/comarnet-app`
   - **Startup file**: `dist/index.js`
   - **Application URL**: `comarnet.com`
4. Click **Create**
5. Click **Restart**

### 6. Verify

Visit `https://comarnet.com` in your browser

---

## 📋 Detailed Instructions

For complete step-by-step instructions, see **DEPLOYMENT_GUIDE.md**

Key sections:
- Step 1: Prepare cPanel Server
- Step 2: Upload Project Files
- Step 3: Configure Environment Variables
- Step 4: Install Dependencies
- Step 5: Configure via cPanel
- Step 6: Configure SSL Certificate
- Step 7: Verify Everything Works
- Step 8: Maintenance & Updates

---

## 🔐 Security Setup

### Database Credentials

1. Create strong MySQL password (16+ characters)
2. Store in `.env.production` (never commit to Git)
3. Backup credentials securely

### JWT Secret

Generate a random string for `JWT_SECRET`:

```bash
# On Linux/Mac
openssl rand -base64 32

# Or use any strong random string generator
```

### SSL Certificate

1. Use cPanel's **AutoSSL** (recommended)
2. Or manually upload SSL certificate
3. Ensure HTTPS is enabled

---

## 📊 Database Setup

### Automatic Setup

The deployment script runs database migrations automatically:

```bash
npm run db:push
```

### Manual Setup

If automatic setup fails:

1. In cPanel, go to **phpMyAdmin**
2. Select your database
3. Go to **SQL** tab
4. Copy contents of `DATABASE_SETUP.sql`
5. Paste and execute

---

## 🔄 Deployment Workflow

### First Deployment

```bash
./deploy.sh                    # Run deployment script
# Then configure in cPanel UI
```

### Subsequent Updates

```bash
# Pull latest code (if using Git)
git pull origin main

# Rebuild
npm run build

# Restart in cPanel UI
# Or via SSH: npm restart
```

---

## 🆘 Troubleshooting

### Application Won't Start

**Check logs:**
```bash
tail -f ~/public_html/comarnet-app/error.log
```

**Common issues:**
- Database credentials incorrect in `.env.production`
- Database not created in cPanel
- Node.js not installed or wrong version

### Database Connection Error

**Test connection:**
```bash
mysql -u comarnet_user -p -h localhost comarnet_prod
```

**If fails:**
- Verify MySQL user created in cPanel
- Check password is correct
- Ensure user has all privileges

### Port Already in Use

**Check what's using port:**
```bash
lsof -i :3000
```

**Kill process if needed:**
```bash
kill -9 [PID]
```

### SSL Certificate Issues

- Check cPanel **AutoSSL** status
- Try manual SSL if AutoSSL fails
- Contact hosting provider if issues persist

---

## 📞 Support

### For cPanel Issues
- Contact your hosting provider
- Check cPanel documentation

### For Node.js Issues
- Check Node.js documentation
- Verify Node.js version (18+)

### For Application Issues
- Check application logs
- Review DEPLOYMENT_GUIDE.md
- Check database connectivity

---

## ✅ Pre-Deployment Checklist

- [ ] MySQL database created in cPanel
- [ ] MySQL user created with strong password
- [ ] `.env.production` file created and configured
- [ ] Database credentials verified
- [ ] JWT_SECRET generated and set
- [ ] All files uploaded to cPanel
- [ ] `deploy.sh` script executed successfully
- [ ] Node.js application created in cPanel
- [ ] Application restarted
- [ ] Website accessible at https://comarnet.com
- [ ] Admin login works
- [ ] Team members can be added/edited
- [ ] SSL certificate active

---

## 🎯 Next Steps After Deployment

1. **Monitor Performance**
   - Check application logs regularly
   - Monitor database performance

2. **Backup Strategy**
   - Set up regular MySQL backups
   - Download backups to secure location

3. **Security**
   - Change default admin password
   - Enable 2FA if available
   - Review access logs

4. **Scaling**
   - Monitor traffic growth
   - Plan for additional resources if needed
   - Consider CDN for static assets

5. **Updates**
   - Keep Node.js updated
   - Update dependencies regularly
   - Monitor security advisories

---

## 📝 File Descriptions

### `.env.production.example`
Template for environment variables. Copy to `.env.production` and fill in your values.

### `DATABASE_SETUP.sql`
SQL script to initialize database tables. Run in phpMyAdmin if automatic setup fails.

### `deploy.sh`
Automated deployment script that:
- Checks Node.js installation
- Installs dependencies
- Runs database migrations
- Builds production files
- Verifies setup

### `DEPLOYMENT_GUIDE.md`
Comprehensive guide with detailed instructions for each deployment step.

---

## 🔗 Useful Links

- [cPanel Documentation](https://docs.cpanel.net/)
- [Node.js Documentation](https://nodejs.org/docs/)
- [MySQL Documentation](https://dev.mysql.com/doc/)
- [Let's Encrypt (SSL)](https://letsencrypt.org/)

---

**Deployment Ready!** Follow the Quick Start guide above to get your website live.
