# cPanel Deployment Guide

## Prerequisites
- cPanel hosting with PHP 8.2+ and MySQL 5.7+
- SSH access (recommended) or File Manager
- Composer installed on server

## Deployment Steps

### 1. Upload Files
Upload all files from the `laracom` directory to your cPanel hosting:
- If using SSH: Use `rsync` or `scp`
- If using File Manager: Upload as ZIP and extract

### 2. Set Document Root
Point your domain's document root to the `public` directory:
- In cPanel → Domains → Domain Settings
- Set Document Root to: `/home/username/public_html/public` (adjust path as needed)

### 3. Configure Environment
```bash
# Copy and edit .env file
cp .env.example .env
nano .env
```

Update these critical settings:
```env
APP_ENV=production
APP_DEBUG=false
APP_URL=https://yourdomain.com

DB_HOST=localhost
DB_DATABASE=your_database_name
DB_USERNAME=your_database_user
DB_PASSWORD=your_database_password
```

### 4. Generate Application Key
```bash
php artisan key:generate
```

### 5. Install Dependencies
```bash
composer install --optimize-autoloader --no-dev
```

### 6. Set Permissions
```bash
chmod -R 755 storage bootstrap/cache
chown -R username:username storage bootstrap/cache
```

### 7. Run Migrations
```bash
php artisan migrate --force
```

### 8. Seed Initial Data (First Time Only)
```bash
php artisan db:seed --class=InstallSeeder
```

This creates:
- Admin user: admin@example.com / password
- Basic settings and configurations

### 9. Link Storage
```bash
php artisan storage:link
```

### 10. Optimize Application
```bash
php artisan config:cache
php artisan route:cache
php artisan view:cache
```

### 11. Build Frontend Assets (if needed)
```bash
npm install
npm run build
```

## .htaccess Configuration

Ensure your `public/.htaccess` has:
```apache
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
```

## Post-Deployment Checklist

- [ ] Test admin login at `/admin`
- [ ] Configure payment gateways in admin panel
- [ ] Configure courier services in admin panel
- [ ] Set up email settings
- [ ] Test order placement
- [ ] Test incomplete orders tracking
- [ ] Verify courier integration

## Updating Existing Installation

### 1. Backup Database
```bash
mysqldump -u username -p database_name > backup_$(date +%Y%m%d).sql
```

### 2. Backup Files
```bash
tar -czf backup_files_$(date +%Y%m%d).tar.gz /path/to/app
```

### 3. Upload New Files
Upload updated files, excluding:
- `.env` (keep your existing one)
- `storage/app/public/*` (keep uploaded files)
- `vendor/` (will be regenerated)
- `node_modules/` (will be regenerated)

### 4. Run Migrations
```bash
php artisan migrate --force
```

### 5. Clear Caches
```bash
php artisan config:clear
php artisan route:clear
php artisan view:clear
php artisan cache:clear
```

### 6. Rebuild Caches
```bash
php artisan config:cache
php artisan route:cache
php artisan view:cache
```

### 7. Rebuild Assets (if changed)
```bash
npm install
npm run build
```

## Troubleshooting

### 500 Internal Server Error
- Check `.env` file exists and is configured
- Verify storage permissions: `chmod -R 755 storage bootstrap/cache`
- Check error logs in `storage/logs/laravel.log`

### Database Connection Error
- Verify database credentials in `.env`
- Ensure database exists
- Check if database user has proper permissions

### Missing Assets
- Run `php artisan storage:link`
- Verify `public/storage` symlink exists
- Check file permissions

### Composer Issues
- Use PHP 8.2+: `php82 /usr/local/bin/composer install`
- Increase memory: `php -d memory_limit=512M /usr/local/bin/composer install`

## Security Recommendations

1. **Disable Directory Listing**
   Add to `.htaccess`: `Options -Indexes`

2. **Protect .env File**
   Already protected by default `.htaccess`

3. **Enable HTTPS**
   Use cPanel SSL/TLS or Let's Encrypt

4. **Set Proper Permissions**
   - Files: 644
   - Directories: 755
   - Storage: 755

5. **Keep Updated**
   Regularly update dependencies: `composer update`

## Support

For issues specific to this deployment:
- Check Laravel logs: `storage/logs/laravel.log`
- Check cPanel error logs
- Review migration files in `database/migrations/`

## New Features in This Update

### Incomplete Orders System
- Tracks abandoned checkouts
- Admin dashboard for incomplete orders
- Fraud detection integration
- Automatic cleanup of old incomplete orders

### Enhanced Courier Integration
- Steadfast: Balance checking and order creation
- Pathao: Store selection and order management
- RedX: Store selection and pickup management
- Courier error logging and retry functionality

### Admin Improvements
- Two-factor authentication
- Admin action logging
- Enhanced order management
- Payment gateway configuration UI
- Courier settings with connection testing

### Frontend Enhancements
- Improved checkout flow
- Better mobile responsiveness
- Enhanced product pages
- Wishlist functionality
- Order tracking
