# Perfect Water Dashboard - Deployment Guide

This guide will help you deploy the Perfect Water Dashboard system to your Afrihost Silver Pro shared hosting package.

## 🎯 **Deployment Overview**

The PHP dashboard system is designed to work perfectly with shared hosting environments that support:
- ✅ PHP 7.4+ (Afrihost supports PHP 8.x)
- ✅ MySQL/MariaDB databases
- ✅ Standard web hosting features

## 📋 **Pre-Deployment Checklist**

- [ ] Afrihost Silver Pro hosting account active
- [ ] Domain name configured and pointing to hosting
- [ ] cPanel access available
- [ ] Database credentials ready
- [ ] All PHP dashboard files ready for upload

## 🚀 **Step-by-Step Deployment**

### **Step 1: Database Setup**

1. **Login to cPanel**
   - Go to your Afrihost ClientZone
   - Access cPanel

2. **Create Database**
   - Navigate to "MySQL Databases"
   - Create a new database: `perfect_water_prod`
   - Create a database user with full privileges
   - Note down the database credentials

3. **Import Schema**
   - Go to "phpMyAdmin"
   - Select your database
   - Import the file: `setup/database-setup.sql`
   - Verify tables are created successfully

### **Step 2: File Upload**

1. **Upload Files via cPanel File Manager**
   ```
   public_html/
   ├── static-website/          # Customer-facing website
   ├── php-dashboards/          # Dashboard system
   │   ├── customer-dashboard/  # Customer portal
   │   ├── backoffice-dashboard/ # Admin portal
   │   └── api/                 # API endpoints
   ```

2. **Set File Permissions**
   - Ensure all PHP files are readable (644)
   - Ensure directories are executable (755)
   - Create `uploads/` directory with write permissions (755)

### **Step 3: Configuration**

1. **Create Environment File**
   - Copy `env.example` to `.env`
   - Update with your database credentials:
   ```env
   DB_HOST=localhost
   DB_NAME=your_database_name
   DB_USER=your_database_user
   DB_PASS=your_database_password
   APP_ENV=production
   APP_URL=https://yourdomain.com
   JWT_SECRET=your-secure-secret-key-here
   ```

2. **Email Configuration**
   ```env
   SMTP_HOST=mail.yourdomain.com
   SMTP_PORT=587
   SMTP_USERNAME=noreply@yourdomain.com
   SMTP_PASSWORD=your-email-password
   SMTP_FROM_EMAIL=noreply@yourdomain.com
   SMTP_FROM_NAME=Perfect Water
   ```

### **Step 4: URL Configuration**

Configure your domain to serve the different parts:

1. **Main Website** (Customer-facing)
   - URL: `https://yourdomain.com/`
   - Points to: `static-website/`

2. **Customer Dashboard**
   - URL: `https://yourdomain.com/customer/`
   - Points to: `php-dashboards/customer-dashboard/`

3. **Admin Dashboard**
   - URL: `https://yourdomain.com/admin/`
   - Points to: `php-dashboards/backoffice-dashboard/`

4. **API Endpoints**
   - URL: `https://yourdomain.com/api/`
   - Points to: `php-dashboards/api/`

### **Step 5: SSL Certificate**

1. **Enable SSL**
   - In cPanel, go to "SSL/TLS"
   - Enable "Force HTTPS Redirect"
   - Install Let's Encrypt certificate (free)

### **Step 6: Testing**

1. **Run System Test**
   - Visit: `https://yourdomain.com/php-dashboards/test.php`
   - Verify all tests pass

2. **Test Customer Dashboard**
   - Visit: `https://yourdomain.com/customer/`
   - Login with: `john.doe@example.com` / `password123`

3. **Test Admin Dashboard**
   - Visit: `https://yourdomain.com/admin/`
   - Login with: `admin@perfectwater.co.za` / `admin123`

## 🔐 **Security Configuration**

### **Change Default Passwords**

1. **Admin Password**
   ```sql
   UPDATE User SET passwordHash = '$2y$10$newhashedpassword' WHERE email = 'admin@perfectwater.co.za';
   ```

2. **Customer Passwords**
   - Use the customer dashboard to change passwords
   - Or update directly in database

### **Environment Security**

1. **Secure .env file**
   - Ensure `.env` is not web-accessible
   - Set proper file permissions (600)

2. **Database Security**
   - Use strong database passwords
   - Limit database user privileges
   - Regular database backups

## 📊 **Post-Deployment Tasks**

### **1. Data Migration (if needed)**
If you have existing data from the Next.js system:
- Export data from old system
- Import into new database structure
- Verify data integrity

### **2. Email Setup**
- Configure SMTP settings
- Test email functionality
- Set up email templates

### **3. Backup Configuration**
- Set up automated database backups
- Configure file backups
- Test restore procedures

### **4. Monitoring Setup**
- Monitor system performance
- Set up error logging
- Configure uptime monitoring

## 🛠️ **Troubleshooting**

### **Common Issues**

1. **Database Connection Failed**
   - Check database credentials in `.env`
   - Verify database exists and user has permissions
   - Check PHP PDO extension is enabled

2. **Permission Denied Errors**
   - Check file permissions (644 for files, 755 for directories)
   - Ensure web server can read files
   - Check directory ownership

3. **Session Issues**
   - Verify PHP sessions are working
   - Check session directory permissions
   - Clear browser cookies and cache

4. **API Endpoints Not Working**
   - Check URL rewriting rules
   - Verify `.htaccess` file is present
   - Test direct file access

### **Debug Mode**

Enable debug mode for troubleshooting:
```env
APP_ENV=development
```

## 📞 **Support**

### **Afrihost Support**
- **Phone**: 0861 234 567
- **Email**: support@afrihost.com
- **Live Chat**: Available in ClientZone

### **Technical Support**
- **Email**: support@perfectwater.co.za
- **Phone**: +27 123 456 789
- **WhatsApp**: +27 123 456 789

## 📈 **Performance Optimization**

### **Shared Hosting Optimizations**

1. **Database Optimization**
   - Regular database maintenance
   - Optimize queries
   - Use indexes effectively

2. **File Optimization**
   - Compress CSS/JS files
   - Optimize images
   - Enable gzip compression

3. **Caching**
   - Use browser caching
   - Implement PHP opcode caching
   - Database query caching

## 🔄 **Maintenance**

### **Regular Tasks**

1. **Weekly**
   - Check system logs
   - Monitor disk space
   - Review error logs

2. **Monthly**
   - Update passwords
   - Review user access
   - Database optimization

3. **Quarterly**
   - Security audit
   - Performance review
   - Backup testing

## ✅ **Deployment Verification**

After deployment, verify:

- [ ] Main website loads correctly
- [ ] Customer dashboard login works
- [ ] Admin dashboard login works
- [ ] API endpoints respond correctly
- [ ] Database operations work
- [ ] Email functionality works
- [ ] SSL certificate is active
- [ ] All forms submit correctly
- [ ] Mobile responsiveness works
- [ ] WhatsApp integration works

## 🎉 **Success!**

Your Perfect Water Dashboard is now successfully deployed and ready for use!

**Access URLs:**
- **Main Website**: https://yourdomain.com/
- **Customer Portal**: https://yourdomain.com/customer/
- **Admin Dashboard**: https://yourdomain.com/admin/
- **API**: https://yourdomain.com/api/

Remember to:
1. Change all default passwords
2. Configure email settings
3. Set up regular backups
4. Monitor system performance
5. Keep the system updated

---

**Perfect Water Dashboard v1.0.0**  
*Deployed successfully on Afrihost Silver Pro Shared Hosting*
