# Deployment Guide for Aakash Digital

## On Your Local Server / Hosting Provider

### Prerequisites
- PHP 8.0+ with MySQLi extension
- MySQL 5.7+
- Apache with mod_rewrite OR Nginx

### Step-by-Step Deployment

#### 1. Extract Files
```bash
# If using tar.gz
tar -xzf v0-project-modernized.tar.gz

# Place in your web directory
mv v0-project/* /var/www/html/aakash-digital/
cd /var/www/html/aakash-digital
```

#### 2. Create Database
```bash
mysql -u root -p << 'EOF'
CREATE DATABASE aakash_digital CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
GRANT ALL PRIVILEGES ON aakash_digital.* TO 'aakash_user'@'localhost' IDENTIFIED BY 'strong_password';
FLUSH PRIVILEGES;
EOF

# Import schema
mysql -u aakash_user -p aakash_digital < database/schema.sql
```

#### 3. Configure Application
Edit `config/config.php`:
```php
define('DB_HOST', 'localhost');
define('DB_USER', 'aakash_user');
define('DB_PASS', 'strong_password');
define('DB_NAME', 'aakash_digital');
define('APP_URL', 'https://yourdomain.com');  // Update to your domain
```

#### 4. File Permissions
```bash
# Set proper permissions
chmod 755 public/
chmod 755 admin/
chmod 755 api/
chmod 755 public/uploads/
chmod 644 config/config.php

# If using Apache
chown -R www-data:www-data /var/www/html/aakash-digital
```

#### 5. Web Server Configuration

**Apache (.htaccess already included)**:
```bash
# Enable mod_rewrite
a2enmod rewrite
systemctl restart apache2
```

Point DocumentRoot to `public/` directory:
```apache
<VirtualHost *:80>
    ServerName yourdomain.com
    DocumentRoot /var/www/html/aakash-digital/public
    
    <Directory /var/www/html/aakash-digital/public>
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>
```

**Nginx Configuration**:
```nginx
server {
    listen 80;
    server_name yourdomain.com;
    root /var/www/html/aakash-digital/public;
    
    index index.php index.html index.htm;
    
    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }
    
    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php8.0-fpm.sock;
    }
    
    location ~ /\.ht {
        deny all;
    }
}
```

#### 6. SSL Certificate (HTTPS)
```bash
# Using Let's Encrypt (Certbot)
sudo apt install certbot python3-certbot-apache
sudo certbot certonly --apache -d yourdomain.com

# Enable in Apache
sudo a2enmod ssl
# Update vhost to include SSL cert paths
```

#### 7. Update Admin Credentials
```bash
# Generate new password hash
php -r "echo password_hash('your_secure_password', PASSWORD_BCRYPT);"

# Update in database
mysql -u aakash_user -p aakash_digital
UPDATE admins SET password = '$2y$10$...' WHERE username = 'admin';
```

## Post-Deployment Checklist

- [ ] Database created and populated
- [ ] config/config.php updated with correct credentials
- [ ] APP_URL set to your domain (with https://)
- [ ] File permissions set correctly
- [ ] Web server configured and pointing to public/ folder
- [ ] Admin password changed from default
- [ ] SSL/HTTPS enabled
- [ ] public/uploads/ directory is writable
- [ ] Database backups scheduled
- [ ] Test admin login works
- [ ] Test contact form submissions work
- [ ] Test API endpoints respond correctly

## Testing

### Admin Panel
1. Navigate to `https://yourdomain.com/admin/login.php`
2. Login with your new credentials
3. Add sample team member
4. Add sample service
5. View dashboard

### Public Site
1. Navigate to `https://yourdomain.com/`
2. Check all pages load correctly
3. Test contact form submission
4. Verify database receives the message

### APIs
```bash
# Test team API
curl https://yourdomain.com/api/team.php

# Test services API
curl https://yourdomain.com/api/services.php

# Test content API
curl https://yourdomain.com/api/content.php?page=home
```

## Performance Optimization

### Enable Caching
1. Enable browser caching in web server config
2. Add cache headers to PHP files:
```php
header('Cache-Control: max-age=3600');
```

### Database Optimization
```sql
-- Create indexes for faster queries
CREATE INDEX idx_page_slug ON content_pages(page_slug);
CREATE INDEX idx_team_order ON team_members(order_num);
CREATE INDEX idx_services_order ON services(order_num);
```

### PHP Configuration (php.ini)
```ini
memory_limit = 256M
upload_max_filesize = 50M
post_max_size = 50M
max_execution_time = 300
```

## Backup Strategy

### Daily Database Backups
```bash
#!/bin/bash
# save as backup.sh
BACKUP_DIR="/backups/aakash-digital"
DATE=$(date +%Y%m%d_%H%M%S)

mysqldump -u aakash_user -p aakash_digital > $BACKUP_DIR/db_$DATE.sql
gzip $BACKUP_DIR/db_$DATE.sql

# Keep only last 30 days
find $BACKUP_DIR -name "*.sql.gz" -mtime +30 -delete
```

### Full Website Backup
```bash
#!/bin/bash
BACKUP_DIR="/backups/aakash-digital"
DATE=$(date +%Y%m%d)
tar -czf $BACKUP_DIR/website_$DATE.tar.gz \
    /var/www/html/aakash-digital/ \
    --exclude=node_modules \
    --exclude=.git
```

Schedule with crontab:
```bash
crontab -e
# Daily at 2 AM
0 2 * * * /path/to/backup.sh
```

## Monitoring & Maintenance

### Monitor Error Logs
```bash
# PHP errors
tail -f /var/log/php-errors.log

# Web server errors
tail -f /var/log/apache2/error.log  # Apache
tail -f /var/log/nginx/error.log    # Nginx
```

### Regular Maintenance
- Update PHP packages: `apt update && apt upgrade php*`
- Update MySQL: `apt upgrade mysql-server`
- Monitor disk space: `df -h`
- Monitor memory: `free -h`
- Check SSL expiration: `certbot renew --dry-run`

## Common Issues & Solutions

### 502 Bad Gateway
- Check PHP-FPM is running: `systemctl status php8.0-fpm`
- Check MySQL is running: `systemctl status mysql`
- Increase PHP max_execution_time

### Database Connection Error
- Verify credentials in config.php
- Check MySQL user has correct privileges
- Verify database name exists: `mysql -e "SHOW DATABASES;"`

### Contact Form Not Saving
- Check public/uploads/ permissions
- Verify database tables exist
- Check MySQL connection logs

### Admin Panel Slow
- Check database for long-running queries
- Enable query caching in MySQL
- Add database indexes (see optimization section)

## Support

For technical issues:
- Email: support@aakashdigital.com
- Documentation: See README.md

---

**Happy deployment!** 🚀
