# mojoPortal 1.0.0-alpha — Deployment Guide

**Version:** 1.0.0-alpha (Alpha Testing)  
**Target Platform:** IIS (IIS Express or Production)  
**Runtime:** .NET Framework 4.8.1  
**Database:** SQLite (self-contained)  

---

## Overview

This guide walks through deploying mojoPortal 1.0.0-alpha from the development environment (`C:\___Work\SqliteMojo`) to a production server and configuring it to be accessible via `https://phosend.com/Portal`.

The deployment includes:
- ✅ Portal application code
- ✅ SQLite database (auto-initializes)
- ✅ Migration system (for legacy data)
- ✅ Admin interface (for management)
- ✅ DevAdmin tools (developer utilities)

---

## Pre-Deployment Checklist

### Server Requirements
- [ ] IIS installed and running
- [ ] .NET Framework 4.8.1 Runtime installed
- [ ] Application pool available (or create new)
- [ ] HTTPS/SSL certificate configured for `https://phosend.com`
- [ ] DNS pointing `phosend.com` to server IP
- [ ] Read/write permissions for app pool identity on deployment directory

### Development Environment
- [ ] Solution builds successfully (`run_build` → Build successful)
- [ ] All tests pass (if applicable)
- [ ] Migration system tested locally
- [ ] DevAdmin Siphon button verified working

### Backup & Safety
- [ ] Source backed up: `C:\___Work\SqliteMojo` (entire directory)
- [ ] Any existing `C:\___Fire\SqliteMojo` backed up
- [ ] Database backup plan established

---

## Deployment Steps

### Step 1: Copy Application Files

**From:** `C:\___Work\SqliteMojo`  
**To:** `C:\___Fire\SqliteMojo`

Using PowerShell as Administrator:

```powershell
# Create target directory if needed
New-Item -ItemType Directory -Path "C:\___Fire\SqliteMojo" -Force

# Copy entire application structure
Copy-Item -Path "C:\___Work\SqliteMojo\*" -Destination "C:\___Fire\SqliteMojo" -Recurse -Force

# Verify copy was successful
Get-ChildItem -Path "C:\___Fire\SqliteMojo" -Recurse | Measure-Object
```

**Verify:**
```
Expected directories: Web/, mojoPortal.Business/, mojoPortal.Data.SQLite/, etc.
Expected files: README.md, VERSION.md, Web.config, etc.
```

### Step 2: Configure IIS

#### Option A: Using IIS Manager (GUI)

1. **Open IIS Manager**
   - Start → Server Manager → Tools → Internet Information Services (IIS) Manager

2. **Create Application Pool** (if needed)
   - Right-click "Application Pools" → Add Application Pool
   - Name: `MojoPortal-v1alpha`
   - .NET CLR Version: `.NET Framework v4.0.30319`
   - Managed Pipeline Mode: `Integrated`
   - Click OK

3. **Set Application Pool Identity**
   - Right-click `MojoPortal-v1alpha` → Advanced Settings
   - Identity: ApplicationPoolIdentity
   - Click OK

4. **Create Web Application**
   - In your website (or create new website if needed)
   - Right-click website → Add Application
   - Alias: `Portal`
   - Application Pool: `MojoPortal-v1alpha`
   - Physical Path: `C:\___Fire\SqliteMojo\Web`
   - Click OK

5. **Configure HTTPS**
   - Right-click `Portal` application → Edit Bindings
   - Binding Type: `https`
   - IP Address: All Unassigned
   - Port: `443`
   - Host Name: `phosend.com`
   - SSL Certificate: Select your certificate
   - Click OK

#### Option B: Using PowerShell (Command Line)

```powershell
# Run as Administrator

# Create Application Pool
New-WebAppPool -Name "MojoPortal-v1alpha" `
    -Force

# Configure Application Pool
$pool = Get-IISAppPool "MojoPortal-v1alpha"
$pool.ManagedRuntimeVersion = "v4.0"
$pool.ManagedPipelineMode = "Integrated"
$pool.ProcessModel.IdentityType = "ApplicationPoolIdentity"
$pool | Set-Item

# Create Web Application
New-WebApplication -Name "Portal" `
    -ApplicationPool "MojoPortal-v1alpha" `
    -PhysicalPath "C:\___Fire\SqliteMojo\Web" `
    -Site "YourSiteName" `
    -Force

# Add HTTPS binding (requires SSL certificate thumbprint)
$cert = Get-ChildItem Cert:\LocalMachine\My | Where-Object {$_.Subject -like "*phosend.com*"}
New-WebBinding -Name "YourSiteName" `
    -IPAddress "*" `
    -Port 443 `
    -HostHeader "phosend.com" `
    -Protocol https `
    -SslFlags 0
```

### Step 3: Verify Permissions

Ensure the app pool identity has necessary permissions:

```powershell
# Get app pool identity
$appPoolName = "MojoPortal-v1alpha"
$appPoolUser = "IIS AppPool\$appPoolName"

# Grant read/write to application directory
icacls "C:\___Fire\SqliteMojo" /grant:r "${appPoolUser}:(OI)(CI)F" /T

# Grant read/write to SQLite database directory specifically
icacls "C:\___Fire\SqliteMojo\Web\Data\sqlitedb" /grant:r "${appPoolUser}:(OI)(CI)F" /T

# Verify permissions
icacls "C:\___Fire\SqliteMojo\Web\Data\sqlitedb" /T
```

### Step 4: Configure Web.config (If Needed)

**Location:** `C:\___Fire\SqliteMojo\Web\Web.config`

Key settings to verify:

```xml
<!-- Database connection string (typically auto-managed for SQLite) -->
<add name="mojoPortal" 
     connectionString="Data Source=|DataDirectory|\sqlitedb\mojo.db.config;Version=3;" 
     providerName="System.Data.SQLite" />

<!-- Debug mode (set to false in production) -->
<compilation debug="false" />

<!-- Allow migrations & admin features -->
<!-- (Already configured; verify "EnableDeveloperMenuInAdminMenu" is true for DevAdmin access) -->
```

### Step 5: Test Portal Access

#### Test HTTP/HTTPS Access

Open your browser and navigate to:

**Test URLs:**
- `https://phosend.com/Portal` — Portal home page
- `https://phosend.com/Portal/Admin` — Admin menu (may require login)
- `https://phosend.com/Portal/DevAdmin` — DevAdmin tools (requires admin)

**Expected Results:**
- ✅ Portal home loads without errors
- ✅ Admin menu accessible (possibly with login redirect)
- ✅ DevAdmin accessible to admin users
- ✅ "Siphon (Migration)" button visible in DevAdmin

#### Troubleshooting Access Issues

| Issue | Cause | Solution |
|-------|-------|----------|
| 404 Not Found | Application not mapped | Verify IIS binding and physical path |
| 403 Forbidden | Permission issue | Check app pool identity permissions |
| SSL Certificate Error | Certificate not trusted | Ensure SSL cert installed and bound |
| Blank page | App error | Check IIS logs: `C:\inetpub\logs\LogFiles\` |
| "Access Denied" | Authentication issue | Ensure user account has permission |

### Step 6: Database Initialization

The portal auto-initializes SQLite on first run:

1. **Navigate to:** `https://phosend.com/Portal`
2. **Watch for:** Database creation messages (may appear in logs)
3. **Verify:** `C:\___Fire\SqliteMojo\Web\Data\sqlitedb\mojo.db.config` exists
4. **Check:** File size > 0 (database created successfully)

**If Database Doesn't Create:**
- Check app pool permissions (read/write to `Data/sqlitedb/`)
- Check IIS logs for specific errors
- Manually verify write access: `icacls "C:\___Fire\SqliteMojo\Web\Data\sqlitedb"`

### Step 7: Admin Account Setup

First time accessing admin features:

1. **Navigate to:** `https://phosend.com/Portal/Admin`
2. **You may see:** Setup wizard or login screen
3. **Create admin account** (if prompted)
4. **Use strong password** (minimum 8 characters, mixed case/numbers)
5. **Verify access** to `/Portal/Admin` with your account

---

## Migration from Legacy System

If you have legacy portal data to migrate:

### Step 1: Obtain Legacy Database

Copy your legacy database to the new location:

```powershell
# Copy legacy database to where migration tools expect it
Copy-Item -Path "C:\OldPortal\legacy.db" `
          -Destination "C:\___Fire\SqliteMojo\Web\Data\sqlitedb\legacy.db.config" `
          -Force
```

### Step 2: Run Migration Inspector

Navigate to (as admin):
```
https://phosend.com/Portal/Admin/MigrationInspector.aspx
```

**Review:**
- Database file status
- Legacy page count
- Module type mapping
- Potential issues

### Step 3: Run Pre-Migration Analysis

Navigate to:
```
https://phosend.com/Portal/Admin/MigrationExecutor.aspx
```

**Click:** "📊 Analyze Only (No Changes)"

**Review:**
- Module definition mappings
- Any warnings about unmapped types
- Statistics of items to be migrated

### Step 4: Execute Migration

**Click:** "🚀 Execute Full Migration"

**Watch:**
- Real-time progress bar
- Item-by-item migration log
- Final success summary

**Expected Results:**
- Pages migrated with hierarchy
- Modules attached to pages
- Settings transferred
- Permissions mapped

### Step 5: Verify Migration

1. **Admin → Pages Management**
   - Verify page hierarchy is correct
   - Check sample pages for content
   - Test editing a page

2. **Admin → Modules**
   - Verify modules are attached to pages
   - Check module settings
   - Test module functionality

3. **Portal Front-End**
   - Verify pages display
   - Check navigation
   - Test module rendering

**See:** `MIGRATION_GUIDE.md` for detailed verification steps

---

## Post-Deployment Configuration

### Site Settings

Navigate to: `https://phosend.com/Portal/Admin/AdminMenu.aspx` → Site Settings

Configure:
- [ ] Site Name
- [ ] Company/Organization Name
- [ ] Contact Email
- [ ] Timezone
- [ ] Theme/Skin
- [ ] Email Settings (SMTP if needed)

### Initial Content

Create basic structure:
- [ ] Home page
- [ ] About page
- [ ] Contact page
- [ ] Site search configuration
- [ ] User roles (if needed)

### Security Hardening

- [ ] Change default admin password
- [ ] Disable any unnecessary modules
- [ ] Review user roles and permissions
- [ ] Set up admin-only access for sensitive pages
- [ ] Enable HTTPS (already configured)

### Monitoring & Maintenance

- [ ] Set up automated database backups
- [ ] Configure email notifications (if applicable)
- [ ] Review application logs periodically
- [ ] Monitor disk space (database growth)
- [ ] Plan security updates

---

## DevAdmin Integration

The "Siphon (Migration)" button is now integrated into DevAdmin for quick access:

### Quick Migration Access

1. **Navigate to:** `https://phosend.com/Portal/DevAdmin/Default.aspx`
2. **Look for:** "Siphon (Migration)" in the tool list
3. **Click:** To access MigrationExecutor directly

### Why This Is Useful

- One-click access from DevAdmin toolbar
- No need to navigate through nested menus
- Clear labeling ("Siphon" indicates data transfer)
- Works for admin-only users on server admin sites
- Simplifies administrator workflows

---

## Routing Architecture Reference

### Internal Routes (ASP.NET)
```
~/ or ~/Portal/                  → Portal home
~/Admin/                         → Admin menu
~/Admin/Pages/                   → Page management
~/Admin/Modules/                 → Module management
~/Admin/MigrationExecutor.aspx   → Migration executor
~/Admin/MigrationInspector.aspx  → Migration inspector
~/DevAdmin/                      → DevAdmin home
~/DevAdmin/Default.aspx          → DevAdmin (Siphon button here)
~/DevAdmin/ServerVariables.aspx  → System info
~/DevAdmin/QueryTool.aspx        → Database query
~/ABdash/                        → Angular2js dashboard
~/MoxOp/                         → Data operations
```

### External URLs (via phosend.com)
```
https://phosend.com/Portal              → Portal home
https://phosend.com/Portal/Admin        → Admin menu
https://phosend.com/Portal/Admin/Pages/ → Page management
https://phosend.com/Portal/DevAdmin     → DevAdmin tools
https://phosend.com/Portal/DevAdmin/Default.aspx  → Siphon button here
```

---

## Backup & Recovery

### Daily Backup Strategy

```powershell
# Create backup schedule (run as Administrator)

$backupDir = "C:\Backups\mojoPortal"
$sourceDb = "C:\___Fire\SqliteMojo\Web\Data\sqlitedb\mojo.db.config"
$timestamp = Get-Date -Format "yyyy-MM-dd_HH-mm-ss"
$backupFile = "$backupDir\mojo.db.config.$timestamp.bak"

# Create backup directory if needed
New-Item -ItemType Directory -Path $backupDir -Force

# Copy database
Copy-Item -Path $sourceDb -Destination $backupFile -Force

# Keep last 30 days only
Get-ChildItem -Path $backupDir -Filter "*.bak" | 
    Where-Object {$_.LastWriteTime -lt (Get-Date).AddDays(-30)} | 
    Remove-Item -Force
```

### Recovery Procedure

If database corruption occurs:

1. **Stop IIS:**
   ```powershell
   Stop-WebAppPool -Name "MojoPortal-v1alpha"
   ```

2. **Restore Backup:**
   ```powershell
   Copy-Item -Path "C:\Backups\mojoPortal\mojo.db.config.2024-01-15_14-30-00.bak" `
             -Destination "C:\___Fire\SqliteMojo\Web\Data\sqlitedb\mojo.db.config" `
             -Force
   ```

3. **Restart IIS:**
   ```powershell
   Start-WebAppPool -Name "MojoPortal-v1alpha"
   ```

4. **Verify Access:**
   Navigate to `https://phosend.com/Portal` and verify it loads

---

## Troubleshooting Deployment Issues

### Common Problems & Solutions

| Problem | Symptoms | Solution |
|---------|----------|----------|
| Application not loading | 404 or blank page | Verify IIS binding, physical path, app pool |
| Permission denied errors | 403 in logs | Check app pool identity permissions on directory |
| Database not created | SQLite file missing | Verify write permission to Data/sqlitedb/ |
| Migration fails | Items not migrated | Check legacy.db.config path, permissions, format |
| Slow response times | Sluggish portal | Check database size, IIS logs for errors |
| SSL certificate errors | HTTPS access fails | Verify certificate installed, binding configured |
| Admin login fails | Can't access /Admin | Check user accounts, role assignments |

### Checking IIS Logs

```powershell
# View recent IIS errors
Get-ChildItem -Path "C:\inetpub\logs\LogFiles" -Recurse -Filter "*.log" | 
    Sort-Object -Property LastWriteTime -Descending | 
    Select-Object -First 1 | 
    Get-Content -Tail 50
```

### Checking Application Logs

```powershell
# If application logs are configured
Get-EventLog -LogName Application -Source "mojoPortal*" -Newest 20
```

---

## Verification Checklist

After deployment, verify:

- [ ] Portal home page loads: `https://phosend.com/Portal`
- [ ] HTTPS working and certificate valid
- [ ] Admin login functional: `https://phosend.com/Portal/Admin`
- [ ] DevAdmin accessible to admin users: `https://phosend.com/Portal/DevAdmin`
- [ ] "Siphon" button visible in DevAdmin
- [ ] Database file exists: `C:\___Fire\SqliteMojo\Web\Data\sqlitedb\mojo.db.config`
- [ ] Database size > 0 bytes (created successfully)
- [ ] Pages visible in Admin → Pages Management
- [ ] Migration Inspector loads: `/Admin/MigrationInspector.aspx`
- [ ] Migration Executor loads: `/Admin/MigrationExecutor.aspx`
- [ ] No errors in IIS logs
- [ ] Admin can create and publish pages
- [ ] Regular users can view pages with correct permissions

---

## Performance Tuning

### IIS Optimization

```powershell
# Increase application pool capacity
$pool = Get-IISAppPool "MojoPortal-v1alpha"
$pool.ProcessModel.MaxProcesses = 4  # Increase for high traffic
$pool | Set-Item
```

### Database Optimization

For large databases (> 10K items), consider:
- Indexing frequently searched columns
- Archiving old content to separate database
- Enabling SQLite query optimization
- Increasing database connection pool size in Web.config

---

## Next Steps

1. ✅ Complete deployment using steps above
2. ✅ Verify all components accessible
3. ✅ Set up administrator accounts
4. ✅ Create initial site content
5. ✅ If migrating: Follow MIGRATION_GUIDE.md
6. ✅ Configure backups
7. ✅ Monitor logs for issues
8. ✅ Report any landmarks or issues encountered

---

## Support & Documentation

**Key Documents:**
- `README.md` — Project overview and quick start
- `VERSION.md` — Version info and upgrade path
- `MIGRATION_GUIDE.md` — Comprehensive migration guide
- `DEPLOYMENT.md` — This document

**In-Application Help:**
- Admin menu: Hover over items for tooltips
- Migration pages: Include inline instructions
- DevAdmin: Tool descriptions provided

---

## Contact & Feedback

During alpha testing, report:
- Successful deployment milestone
- Migration completion status
- Performance observations
- Any errors or unexpected behavior
- Suggestions for improvement

**When Reporting Issues:**
- Include specific error messages
- Share relevant log excerpts
- Provide exact reproduction steps
- Describe your server environment

---

**mojoPortal 1.0.0-alpha Deployment Guide Complete** ✅

Version: 1.0.0-alpha | Date: 2024 | Status: Ready for Alpha Testing
