# Deployment Checklist

Use this checklist when deploying or updating the application on cPanel.

## Pre-Deployment

### Backup (For Updates Only)
- [ ] Backup database: `mysqldump -u user -p dbname > backup.sql`
- [ ] Backup `.env` file: `cp .env .env.backup`
- [ ] Backup uploaded files: `tar -czf uploads.tar.gz storage/app/public`
- [ ] Note current application version/commit

### Preparation
- [ ] Verify PHP version is 8.2 or higher
- [ ] Verify MySQL/MariaDB version
- [ ] Ensure Composer is available
- [ ] Ensure Node.js and NPM are available (if rebuilding assets)
- [ ] Have database credentials ready
- [ ] Have domain/URL ready

## Deployment Steps

### 1. File Upload
- [ ] Upload all files from `laracom` directory
- [ ] Exclude `.env` if updating (keep existing)
- [ ] Exclude `storage/app/public/*` if updating (keep uploads)
- [ ] Set correct file permissions (755 for dirs, 644 for files)

### 2. Environment Configuration
- [ ] Copy `.env.example` to `.env`
- [ ] Set `APP_ENV=production`
- [ ] Set `APP_DEBUG=false`
- [ ] Set `APP_URL` to your domain
- [ ] Configure database credentials
- [ ] Generate app key: `php artisan key:generate`

### 3. Dependencies
- [ ] Run `composer install --optimize-autoloader --no-dev`
- [ ] Verify vendor directory is created
- [ ] Check for any composer errors

### 4. Database Setup
- [ ] Create database if new installation
- [ ] Run migrations: `php artisan migrate --force`
- [ ] Run seeder (first time only): `php artisan db:seed --class=InstallSeeder`
- [ ] Verify tables are created

### 5. Storage & Permissions
- [ ] Create storage link: `php artisan storage:link`
- [ ] Set storage permissions: `chmod -R 755 storage bootstrap/cache`
- [ ] Verify `public/storage` symlink exists
- [ ] Test file upload functionality

### 6. Optimization
- [ ] Clear all caches: `php artisan config:clear && php artisan route:clear && php artisan view:clear`
- [ ] Cache config: `php artisan config:cache`
- [ ] Cache routes: `php artisan route:cache`
- [ ] Cache views: `php artisan view:cache`

### 7. Frontend Assets (If Changed)
- [ ] Run `npm install`
- [ ] Run `npm run build`
- [ ] Verify assets in `public/build` directory
- [ ] Clear browser cache

### 8. Web Server Configuration
- [ ] Set document root to `public` directory
- [ ] Verify `.htaccess` is present in `public` directory
- [ ] Test URL rewriting works
- [ ] Enable HTTPS/SSL if available

## Post-Deployment Testing

### Basic Functionality
- [ ] Homepage loads correctly
- [ ] Admin login works (`/admin`)
- [ ] Change default admin password
- [ ] Product pages load
- [ ] Category pages load
- [ ] Search functionality works

### E-commerce Features
- [ ] Add product to cart
- [ ] View cart
- [ ] Proceed to checkout
- [ ] Test guest checkout
- [ ] Test registered user checkout
- [ ] Verify order creation

### Admin Panel
- [ ] Dashboard loads with statistics
- [ ] Product management works
- [ ] Order management works
- [ ] Customer management works
- [ ] Settings can be updated

### Payment Gateways
- [ ] Configure payment gateway credentials
- [ ] Test COD orders
- [ ] Test online payment (if configured)
- [ ] Verify payment transactions are logged

### Courier Integration
- [ ] Navigate to Settings → Couriers
- [ ] Configure Steadfast (if using)
  - [ ] Enter API credentials
  - [ ] Test connection
  - [ ] Verify balance displays
- [ ] Configure Pathao (if using)
  - [ ] Enter API credentials
  - [ ] Test connection
  - [ ] Select primary store
  - [ ] Verify store info displays
- [ ] Configure RedX (if using)
  - [ ] Enter API token
  - [ ] Test connection
  - [ ] Select primary store
  - [ ] Verify store info displays

### Incomplete Orders
- [ ] Start checkout process but don't complete
- [ ] Verify incomplete order appears in admin
- [ ] Test incomplete order conversion
- [ ] Check fraud detection works

### Email & Notifications
- [ ] Configure email settings
- [ ] Test order confirmation email
- [ ] Test password reset email
- [ ] Test contact form submission

### Performance
- [ ] Check page load times
- [ ] Verify images load correctly
- [ ] Test on mobile devices
- [ ] Check browser console for errors

## Security Checklist

### Application Security
- [ ] `APP_DEBUG=false` in production
- [ ] Strong `APP_KEY` generated
- [ ] Default admin password changed
- [ ] `.env` file is protected (not web accessible)
- [ ] File permissions are correct (not 777)

### Server Security
- [ ] HTTPS/SSL enabled
- [ ] Firewall configured
- [ ] Database user has minimal required permissions
- [ ] Directory listing disabled
- [ ] Error reporting disabled in production

### Ongoing Security
- [ ] Set up regular backups
- [ ] Monitor error logs
- [ ] Keep dependencies updated
- [ ] Review admin logs regularly
- [ ] Monitor for suspicious activity

## Troubleshooting

### If Something Goes Wrong

#### 500 Internal Server Error
1. Check `storage/logs/laravel.log`
2. Verify `.env` file exists and is configured
3. Check file permissions
4. Clear all caches
5. Check web server error logs

#### Database Connection Error
1. Verify database credentials in `.env`
2. Ensure database exists
3. Check database user permissions
4. Test connection from command line

#### Assets Not Loading
1. Verify `public/storage` symlink exists
2. Run `php artisan storage:link`
3. Check file permissions
4. Clear browser cache
5. Rebuild assets with `npm run build`

#### Composer Issues
1. Check PHP version: `php -v`
2. Increase memory limit: `php -d memory_limit=512M composer install`
3. Use specific PHP version: `php82 composer install`
4. Clear composer cache: `composer clear-cache`

## Rollback Procedure (If Needed)

### Quick Rollback
1. [ ] Restore database: `mysql -u user -p dbname < backup.sql`
2. [ ] Restore `.env`: `cp .env.backup .env`
3. [ ] Restore uploads: `tar -xzf uploads.tar.gz`
4. [ ] Clear caches: `php artisan config:clear && php artisan cache:clear`
5. [ ] Test application

### Full Rollback
1. [ ] Remove new files
2. [ ] Restore complete backup
3. [ ] Restore database
4. [ ] Clear all caches
5. [ ] Test application

## Monitoring & Maintenance

### Daily
- [ ] Check error logs
- [ ] Monitor order processing
- [ ] Check courier integration status

### Weekly
- [ ] Review admin logs
- [ ] Check incomplete orders
- [ ] Monitor fraud detection alerts
- [ ] Review courier error logs

### Monthly
- [ ] Database backup
- [ ] Update dependencies (if needed)
- [ ] Review and clean old logs
- [ ] Performance optimization
- [ ] Security audit

## Support Resources

- Application logs: `storage/logs/laravel.log`
- Laravel docs: https://laravel.com/docs
- Deployment guide: `CPANEL_DEPLOYMENT.md`
- Update guide: `UPDATE_INSTRUCTIONS.md`
- Feature docs: `COURIER_SETTINGS_IMPLEMENTATION.md`

---

**Deployment Date**: _______________
**Deployed By**: _______________
**Version/Commit**: _______________
**Notes**: _______________
