# MiMSMS Voter System - Complete Setup Instructions

This guide will help you set up the MiMSMS Voter System on your cPanel hosting with all voter data pre-loaded.

## What's Included

✅ **63 Districts** across Bangladesh  
✅ **305 Thanas** (sub-divisions)  
✅ **317 Electoral Areas** with complete voter data  
✅ **Pre-loaded voter counts** by mobile operator (Grameenphone, Robi/Airtel, Banglalink)  
✅ **Admin user** ready to use  
✅ **WHMCS integration** configured and ready  

## Prerequisites

- cPanel/WHM hosting account
- PHP 8.1+ support
- MySQL/MariaDB database
- SSH access (recommended)

## Step-by-Step Setup

### Step 1: Upload Files to cPanel

1. Log in to cPanel
2. Go to **File Manager**
3. Navigate to `public_html`
4. Create a folder: `mimsms`
5. Upload all project files to this folder
6. Extract if needed

**Alternative (via SSH):**
```bash
ssh username@your-domain.com
cd public_html
# Upload files here
```

### Step 2: Create Database

1. In cPanel, go to **MySQL Databases**
2. Create new database: `mimsms_voter`
3. Create new user: `mimsms_user`
4. Set password: `your_secure_password`
5. Assign user to database with ALL privileges

### Step 3: Configure Environment

1. In project folder, copy `.env.example` to `.env`:
   ```bash
   cp .env.example .env
   ```

2. Edit `.env` file with your settings:
   ```
   APP_NAME="MiMSMS Voter System"
   APP_ENV=production
   APP_DEBUG=false
   APP_KEY=base64:YOUR_APP_KEY_HERE
   APP_URL=https://your-domain.com/mimsms

   DB_CONNECTION=mysql
   DB_HOST=localhost
   DB_PORT=3306
   DB_DATABASE=mimsms_voter
   DB_USERNAME=mimsms_user
   DB_PASSWORD=your_secure_password

   WHMCS_API_URL=https://your-whmcs-domain.com/includes/api.php
   WHMCS_API_USERNAME=admin
   WHMCS_API_KEY=your_whmcs_api_key
   ```

### Step 4: Generate App Key

```bash
cd /home/username/public_html/mimsms
php artisan key:generate
```

### Step 5: Set File Permissions

```bash
chmod -R 755 storage
chmod -R 755 bootstrap/cache
chmod -R 777 storage
chmod -R 777 bootstrap/cache
```

### Step 6: Run Migrations

```bash
php artisan migrate --force
```

### Step 7: Seed Database with Voter Data

This will populate all 63 districts, 305 thanas, 317 electoral areas, and voter counts:

```bash
php artisan db:seed --class=DatabaseSeeder
```

**Output should show:**
```
✓ Processed 63 districts
✓ Processed 305 thanas
✓ Processed 317 electoral areas
✓ Database seeding completed!
Admin user created: admin@mimsms.com / admin123456
```

### Step 8: Verify Installation

1. Visit your domain: `https://your-domain.com/mimsms`
2. You should see the home page with area selection
3. Try selecting a district to verify data is loaded

### Step 9: Login as Admin

1. Click "Login" in the top navigation
2. Use credentials:
   - **Email**: admin@mimsms.com
   - **Password**: admin123456
3. Go to Admin Dashboard to verify everything works

## Default Admin Credentials

- **Email**: admin@mimsms.com
- **Password**: admin123456

**⚠️ Important**: Change this password immediately after first login!

## Test the System

### 1. Test Area Selection
- Go to home page
- Select any district (e.g., "Dhaka")
- Select a thana
- Select an electoral area
- Click "View Voter Data"
- Verify voter counts display correctly

### 2. Test Order Creation
- Click "New Order" (requires login)
- Select an electoral area
- Fill in customer details
- Select package type
- Submit order
- Verify confirmation page shows

### 3. Test Admin Panel
- Log in as admin
- Go to Admin Dashboard
- Verify statistics show correct counts
- View recent orders

## WHMCS Integration Setup

1. Get your WHMCS API credentials:
   - WHMCS API URL
   - API Username
   - API Key

2. Update `.env` file:
   ```
   WHMCS_API_URL=https://your-whmcs.com/includes/api.php
   WHMCS_API_USERNAME=your_username
   WHMCS_API_KEY=your_api_key
   ```

3. Test order creation to verify integration works

## Troubleshooting

### Database Connection Error
```bash
# Verify credentials in .env
# Check MySQL is running
# Ensure user has proper privileges
```

### Permission Errors
```bash
chmod -R 777 storage bootstrap/cache
```

### Blank Page / 500 Error
```bash
# Check error logs
tail -f storage/logs/laravel.log

# Clear cache
php artisan cache:clear
php artisan config:clear
```

### Data Not Loading
```bash
# Verify seeder ran successfully
php artisan db:seed --class=VoterDataSeeder

# Check database
php artisan tinker
# In tinker: District::count()
```

## Important Files

- `.env` - Configuration (KEEP SECURE!)
- `voter_data.json` - Source data for seeding
- `storage/logs/laravel.log` - Error logs
- `database/seeders/VoterDataSeeder.php` - Voter data seeder

## Maintenance

### Regular Backups
```bash
# Backup database
mysqldump -u mimsms_user -p mimsms_voter > backup.sql

# Backup files
tar -czf mimsms_backup.tar.gz /home/username/public_html/mimsms
```

### Update Dependencies
```bash
composer update
php artisan migrate
```

### Clear Cache
```bash
php artisan cache:clear
php artisan config:clear
php artisan view:clear
```

## Security Recommendations

1. **Change default admin password** immediately
2. **Keep .env file secure** - never commit to Git
3. **Use strong database password**
4. **Enable HTTPS** on your domain
5. **Disable APP_DEBUG** in production
6. **Regular backups** of database and files
7. **Update Laravel** regularly

## Support

- See **README.md** for full documentation
- See **DEPLOYMENT_GUIDE.md** for detailed deployment info
- See **QUICK_START.md** for quick reference
- Laravel docs: https://laravel.com/docs

## Data Summary

| Item | Count |
|------|-------|
| Districts | 63 |
| Thanas | 305 |
| Electoral Areas | 317 |
| Total Voters | 100+ million |

All voter data is organized hierarchically and searchable through the cascading dropdown interface.

---

**Setup Complete!** Your MiMSMS Voter System is ready to use.
