# RoutexShipping - Deployment Checklist

## Pre-Deployment Checklist

### Database Setup
- [ ] Create MySQL database
- [ ] Run database initialization (init_db.php)
- [ ] Verify all tables created
- [ ] Test database connection
- [ ] Create database backup

### File System
- [ ] Create uploads directory
- [ ] Set proper permissions (755)
- [ ] Verify .htaccess file exists
- [ ] Check file ownership
- [ ] Verify write permissions

### Configuration
- [ ] Update database credentials
- [ ] Set APP_URL to production domain
- [ ] Configure SMTP settings
- [ ] Update company information
- [ ] Set up API keys (if needed)

### Security
- [ ] Change default admin password
- [ ] Enable HTTPS/SSL
- [ ] Configure secure cookies
- [ ] Set up firewall rules
- [ ] Enable mod_rewrite in Apache
- [ ] Disable directory listing
- [ ] Set proper file permissions

### Testing
- [ ] Test homepage loading
- [ ] Test tracking functionality
- [ ] Test admin login
- [ ] Test parcel creation
- [ ] Test email sending
- [ ] Test file uploads
- [ ] Test contact form
- [ ] Test responsive design

### Performance
- [ ] Enable caching
- [ ] Optimize database
- [ ] Compress images
- [ ] Minify CSS/JS
- [ ] Set up CDN (optional)
- [ ] Configure backups

### Monitoring
- [ ] Set up error logging
- [ ] Configure email alerts
- [ ] Monitor server resources
- [ ] Track user activity
- [ ] Monitor email delivery

---

## Development Environment Setup

### Step 1: Install Requirements
```bash
# Verify PHP version
php -v

# Verify MySQL is running
mysql -u root -p

# Check Apache modules
apache2ctl -M | grep rewrite
```

### Step 2: Create Database
```sql
CREATE DATABASE routex_shipping CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
```

### Step 3: Initialize Database
```
Visit: http://localhost/routex/config/init_db.php
```

### Step 4: Create Uploads Directory
```bash
mkdir uploads
chmod 755 uploads
```

### Step 5: Test Installation
```
Homepage: http://localhost/routex/
Admin: http://localhost/routex/admin/login
```

---

## Production Deployment

### Step 1: Prepare Server
```bash
# Update system
sudo apt-get update
sudo apt-get upgrade

# Install PHP and MySQL
sudo apt-get install php mysql-server

# Enable mod_rewrite
sudo a2enmod rewrite
sudo systemctl restart apache2
```

### Step 2: Deploy Files
```bash
# Upload files to server
scp -r routex/ user@server:/var/www/html/

# Set permissions
chmod 755 /var/www/html/routex
chmod 755 /var/www/html/routex/uploads
```

### Step 3: Configure Database
```bash
# Create database
mysql -u root -p < database.sql

# Or run initialization
curl http://yourdomain.com/routex/config/init_db.php
```

### Step 4: Configure Web Server
```apache
<VirtualHost *:80>
    ServerName yourdomain.com
    DocumentRoot /var/www/html/routex
    
    <Directory /var/www/html/routex>
        AllowOverride All
        Require all granted
    </Directory>
    
    # Redirect HTTP to HTTPS
    Redirect permanent / https://yourdomain.com/
</VirtualHost>

<VirtualHost *:443>
    ServerName yourdomain.com
    DocumentRoot /var/www/html/routex
    
    SSLEngine on
    SSLCertificateFile /path/to/certificate.crt
    SSLCertificateKeyFile /path/to/private.key
    
    <Directory /var/www/html/routex>
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>
```

### Step 5: Configure HTTPS
```bash
# Install Let's Encrypt SSL
sudo apt-get install certbot python3-certbot-apache

# Generate certificate
sudo certbot certonly --apache -d yourdomain.com

# Auto-renew
sudo systemctl enable certbot.timer
```

### Step 6: Configure Firewall
```bash
# Allow HTTP and HTTPS
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp

# Allow SSH
sudo ufw allow 22/tcp

# Enable firewall
sudo ufw enable
```

### Step 7: Set Up Backups
```bash
# Create backup script
#!/bin/bash
BACKUP_DIR="/backups"
DATE=$(date +%Y%m%d_%H%M%S)

# Backup database
mysqldump -u root -p routex_shipping > $BACKUP_DIR/db_$DATE.sql

# Backup files
tar -czf $BACKUP_DIR/files_$DATE.tar.gz /var/www/html/routex

# Keep only last 30 days
find $BACKUP_DIR -mtime +30 -delete
```

### Step 8: Configure Monitoring
```bash
# Install monitoring tools
sudo apt-get install htop iotop nethogs

# Set up log rotation
sudo nano /etc/logrotate.d/routex
```

---

## Post-Deployment

### Verification
- [ ] Test all pages load correctly
- [ ] Verify HTTPS is working
- [ ] Test admin login
- [ ] Test parcel creation
- [ ] Test email sending
- [ ] Check error logs
- [ ] Monitor server resources

### Optimization
- [ ] Enable caching headers
- [ ] Optimize database queries
- [ ] Compress static assets
- [ ] Set up CDN
- [ ] Monitor performance

### Security Hardening
- [ ] Run security scan
- [ ] Update all dependencies
- [ ] Configure WAF (Web Application Firewall)
- [ ] Set up intrusion detection
- [ ] Regular security audits

### Maintenance
- [ ] Schedule regular backups
- [ ] Monitor disk space
- [ ] Update PHP and MySQL
- [ ] Review error logs
- [ ] Monitor email delivery

---

## Troubleshooting

### Database Connection Error
```
Check:
1. MySQL is running
2. Credentials are correct
3. Database exists
4. User has proper permissions
```

### 404 Errors
```
Check:
1. .htaccess file exists
2. mod_rewrite is enabled
3. AllowOverride is set to All
4. Apache is restarted
```

### Email Not Sending
```
Check:
1. SMTP settings are correct
2. Credentials are valid
3. Firewall allows SMTP port
4. Email logs for errors
```

### File Upload Issues
```
Check:
1. uploads directory exists
2. Permissions are 755
3. Disk space available
4. File size limits
```

### Performance Issues
```
Check:
1. Database indexes
2. Query performance
3. Server resources
4. Cache configuration
```

---

## Maintenance Schedule

### Daily
- [ ] Monitor error logs
- [ ] Check server resources
- [ ] Verify backups completed

### Weekly
- [ ] Review email logs
- [ ] Check parcel statistics
- [ ] Monitor user activity

### Monthly
- [ ] Database optimization
- [ ] Security audit
- [ ] Performance review
- [ ] Backup verification

### Quarterly
- [ ] Update dependencies
- [ ] Security assessment
- [ ] Capacity planning
- [ ] Disaster recovery test

### Annually
- [ ] Full security audit
- [ ] Performance optimization
- [ ] Disaster recovery drill
- [ ] Compliance review

---

## Rollback Plan

### If Deployment Fails
1. Stop web server
2. Restore from backup
3. Verify database
4. Restart services
5. Test functionality

### Backup Restoration
```bash
# Restore database
mysql -u root -p routex_shipping < backup.sql

# Restore files
tar -xzf backup.tar.gz -C /var/www/html/
```

---

## Performance Benchmarks

### Target Metrics
- Page load time: < 2 seconds
- Database query time: < 100ms
- Email delivery: < 5 seconds
- Uptime: 99.9%

### Monitoring Tools
- Google PageSpeed Insights
- GTmetrix
- New Relic
- DataDog

---

## Security Hardening

### Apache Configuration
```apache
# Disable directory listing
<Directory /var/www/html/routex>
    Options -Indexes
</Directory>

# Set security headers
Header set X-Content-Type-Options "nosniff"
Header set X-Frame-Options "SAMEORIGIN"
Header set X-XSS-Protection "1; mode=block"
```

### PHP Configuration
```php
# Disable dangerous functions
disable_functions = exec,passthru,shell_exec,system,proc_open,popen,curl_exec,curl_multi_exec,parse_ini_file,show_source

# Set limits
max_execution_time = 30
max_input_time = 60
memory_limit = 128M
upload_max_filesize = 5M
```

### MySQL Configuration
```sql
# Create restricted user
CREATE USER 'routex'@'localhost' IDENTIFIED BY 'strong_password';
GRANT SELECT, INSERT, UPDATE, DELETE ON routex_shipping.* TO 'routex'@'localhost';
FLUSH PRIVILEGES;
```

---

## Disaster Recovery

### Backup Strategy
- Daily incremental backups
- Weekly full backups
- Monthly archive backups
- Off-site backup storage

### Recovery Time Objectives (RTO)
- Critical systems: 1 hour
- Important systems: 4 hours
- Non-critical systems: 24 hours

### Recovery Point Objectives (RPO)
- Critical data: 1 hour
- Important data: 4 hours
- Non-critical data: 24 hours

---

## Compliance & Regulations

### Data Protection
- [ ] GDPR compliance
- [ ] Data encryption
- [ ] Privacy policy
- [ ] Terms of service

### Security Standards
- [ ] PCI DSS (if handling payments)
- [ ] ISO 27001
- [ ] SOC 2

### Audit Trail
- [ ] User activity logging
- [ ] Admin action logging
- [ ] Email delivery logging
- [ ] Error logging

---

## Support & Documentation

### Internal Documentation
- [ ] System architecture
- [ ] Database schema
- [ ] API documentation
- [ ] Troubleshooting guide

### User Documentation
- [ ] Admin manual
- [ ] User guide
- [ ] FAQ
- [ ] Video tutorials

### Contact Information
- [ ] Support email
- [ ] Support phone
- [ ] Support hours
- [ ] Escalation procedure

---

## Sign-Off

- [ ] Development Lead: _________________ Date: _______
- [ ] QA Lead: _________________ Date: _______
- [ ] Operations Lead: _________________ Date: _______
- [ ] Security Lead: _________________ Date: _______

---

**Deployment Status**: Ready for Production ✅

**Version**: 1.0.0  
**Date**: 2024  
**Environment**: Production

---

For questions or issues, refer to the documentation or contact support.
