# 🚀 Namecheap Post-Installation Guide

You've completed the web installer! Now follow these steps to get your app running.

---

## 🗑️ STEP 1: Delete /install Folder (Security)

### **Via cPanel File Manager:**

1. **Log into Namecheap cPanel**
2. **Go to:** File Manager
3. **Navigate to:** `public_html/install` (or wherever you uploaded)
4. **Right-click** the `install` folder
5. **Click:** Delete
6. **Confirm** deletion

**Why?** The installer contains sensitive code that could expose your database credentials.

---

## 🎯 STEP 2: Choose Your Namecheap Hosting Type

Namecheap offers different hosting types. Choose based on what you have:

### **Option A: Shared Hosting** (Most Common)
- ⚠️ **Limited Node.js support**
- May not support Next.js properly
- **Not recommended** for this app
- **Alternative:** Deploy to Vercel (free) instead

### **Option B: VPS Hosting** (Recommended)
- ✅ Full control over Node.js
- ✅ SSH access
- ✅ Can run npm commands
- ✅ Best for Next.js apps
- **Continue with steps below**

### **Option C: Use Vercel Instead** (Easiest)
- ✅ Free tier available
- ✅ Perfect for Next.js
- ✅ Auto-deploys from GitHub
- ✅ No server management
- **See "Deploy to Vercel" section below**

---

## 🖥️ FOR NAMECHEAP VPS HOSTING

### **STEP 3: Connect via SSH**

1. **Get SSH credentials** from Namecheap panel
2. **Open terminal** (PowerShell on Windows)
3. **Connect:**
   ```bash
   ssh username@your-server-ip
   ```
4. **Enter password** when prompted

---

### **STEP 4: Navigate to Your App**

```bash
# Find your app directory
cd /home/username/public_html

# Or if in subdirectory
cd /home/username/public_html/rebrandly
```

---

### **STEP 5: Install Node.js (if not installed)**

Check if Node.js is installed:
```bash
node --version
```

**If not installed or version < 18:**

```bash
# Install Node.js 18.x
curl -fsSL https://rpm.nodesource.com/setup_18.x | sudo bash -
sudo yum install -y nodejs

# Verify installation
node --version
npm --version
```

---

### **STEP 6: Install Dependencies**

```bash
# Make sure you're in the app directory
pwd  # Should show /home/username/public_html

# Install all packages
npm install

# This will take 2-5 minutes
# You'll see progress bars
```

**Expected output:**
```
added 500+ packages in 3m
```

---

### **STEP 7: Build the Application**

```bash
npm run build
```

**Expected output:**
```
✓ Compiled successfully
✓ Collecting page data
✓ Generating static pages
✓ Finalizing page optimization
```

**This takes 1-3 minutes**

---

### **STEP 8: Start the Application**

**Option A: Direct Start (for testing)**
```bash
npm start
```

**Access at:** `http://your-server-ip:3000`

**Problem:** Stops when you close SSH

---

**Option B: PM2 (Recommended for Production)**

```bash
# Install PM2 globally
npm install -g pm2

# Start the app
pm2 start npm --name "rebrandly" -- start

# Make it auto-start on server reboot
pm2 startup
pm2 save

# Check status
pm2 status

# View logs
pm2 logs rebrandly
```

---

### **STEP 9: Configure Nginx Reverse Proxy**

To access at `https://rebrandlyai.com` instead of `http://ip:3000`:

**Create Nginx config:**
```bash
sudo nano /etc/nginx/conf.d/rebrandly.conf
```

**Add this:**
```nginx
server {
    listen 80;
    server_name rebrandlyai.com www.rebrandlyai.com;

    location / {
        proxy_pass http://localhost:3000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}
```

**Save and restart Nginx:**
```bash
sudo nginx -t
sudo systemctl restart nginx
```

---

### **STEP 10: Set Up SSL Certificate (HTTPS)**

```bash
# Install Certbot
sudo yum install certbot python3-certbot-nginx

# Get SSL certificate
sudo certbot --nginx -d rebrandlyai.com -d www.rebrandlyai.com

# Follow prompts
# Choose: Redirect HTTP to HTTPS
```

**Auto-renewal:**
```bash
sudo certbot renew --dry-run
```

---

## 🌐 FOR SHARED HOSTING (Not Recommended)

If you have shared hosting, Next.js won't work well. **Use Vercel instead:**

---

## ☁️ DEPLOY TO VERCEL (RECOMMENDED FOR SHARED HOSTING)

### **Why Vercel?**
- ✅ Built for Next.js
- ✅ Free tier (hobby plan)
- ✅ Automatic HTTPS
- ✅ Auto-deploys on Git push
- ✅ No server management
- ✅ Your database stays on Namecheap

---

### **Steps:**

**1. Push Code to GitHub**

```bash
# On your local machine
cd C:\Users\hp\Documents\rev1111111

# Initialize Git (if not already)
git init

# Add all files
git add .

# Commit
git commit -m "Initial commit"

# Create repo on GitHub (github.com/new)
# Then push:
git remote add origin https://github.com/yourusername/rebrandly.git
git branch -M main
git push -u origin main
```

**2. Connect to Vercel**

1. Go to **vercel.com**
2. **Sign up** with GitHub
3. **Click:** New Project
4. **Import** your repository
5. **Framework:** Next.js (auto-detected)
6. **Click:** Deploy

**3. Add Environment Variables**

In Vercel dashboard:
1. Go to **Settings** → **Environment Variables**
2. Add all variables from your `.env` file:
   - `MYSQL_HOST` = Your Namecheap database host
   - `MYSQL_USER` = Your database user
   - `MYSQL_PASSWORD` = Your database password
   - `MYSQL_DATABASE` = Your database name
   - `SMTP_HOST` = business187.web-hosting.com
   - `SMTP_PASS` = Your email password
   - `GROQ_API_KEY` = Your Groq key
   - etc.

**4. Redeploy**

Click **Deployments** → **Redeploy**

**5. Configure Custom Domain**

1. In Vercel: **Settings** → **Domains**
2. Add: `rebrandlyai.com`
3. In Namecheap DNS:
   - Add **A record**: `@` → Vercel IP
   - Add **CNAME**: `www` → `cname.vercel-dns.com`
4. Wait for DNS propagation (5-60 minutes)

---

## ✅ Verification Checklist

After deployment:

- [ ] `/install` folder deleted
- [ ] App accessible at your domain
- [ ] HTTPS working (green padlock)
- [ ] Sign up works
- [ ] Email verification sent
- [ ] Login works
- [ ] Dashboard loads
- [ ] Database connected
- [ ] Stripe webhooks configured (if using Stripe)

---

## 🔍 Troubleshooting

### **"npm: command not found"**
- Node.js not installed
- Install Node.js 18+ on VPS

### **"Port 3000 already in use"**
```bash
# Kill process on port 3000
sudo lsof -ti:3000 | xargs kill -9
```

### **"Cannot connect to database"**
- Check `.env` has correct credentials
- Verify database allows remote connections
- Check MySQL user has privileges

### **"502 Bad Gateway"**
- App not running
- Check: `pm2 status`
- Restart: `pm2 restart rebrandly`

### **Vercel deployment fails**
- Check build logs in Vercel dashboard
- Verify all environment variables are set
- Check database connection from Vercel

---

## 📊 Summary

**For VPS Hosting:**
1. Delete `/install` folder
2. SSH into server
3. Run: `npm install`
4. Run: `npm run build`
5. Run: `pm2 start npm --name rebrandly -- start`
6. Configure Nginx + SSL
7. Access at your domain

**For Shared Hosting:**
1. Delete `/install` folder
2. Push code to GitHub
3. Deploy to Vercel
4. Add environment variables
5. Configure custom domain
6. Access at your domain

---

## 🎉 You're Done!

Your Rebrandly AI application is now live at:
**https://rebrandlyai.com**

Test all features:
- Sign up
- Email verification
- Login
- Dashboard
- Billing
- AI rebranding

---

**Need help?** Check the error logs:
- VPS: `pm2 logs rebrandly`
- Vercel: Dashboard → Deployments → View Logs
