# Q ROVER - Shared Hosting Deployment Guide

This guide will help you deploy Q ROVER to shared hosting environments like cPanel, Plesk, or similar hosting providers.

## 📋 Pre-Deployment Checklist

### Requirements
- PHP 8.2 or higher
- MySQL 5.7 or higher
- Composer (for local optimization)
- SSH access (recommended) or File Manager access

### Files to Prepare
- [ ] Update `.env` file with production settings
- [ ] Run optimization commands locally
- [ ] Test application locally
- [ ] Backup existing data (if upgrading)

## 🚀 Deployment Steps

### Step 1: Prepare Your Local Environment

1. **Clone/Download the project**
   ```bash
   git clone <repository-url>
   cd QROVER9
   ```

2. **Install dependencies and optimize**
   ```bash
   composer install --no-dev --optimize-autoloader
   php artisan config:cache
   php artisan route:cache
   php artisan view:cache
   ```

3. **Create production environment file**
   ```bash
   cp .env.production .env
   # Edit .env with your production settings
   ```

### Step 2: Database Setup

1. **Create MySQL Database**
   - Log into your hosting control panel (cPanel/Plesk)
   - Create a new MySQL database
   - Create a database user with full privileges
   - Note down: database name, username, password, host

2. **Update Database Configuration**
   ```env
   DB_CONNECTION=mysql
   DB_HOST=localhost  # or your host's database server
   DB_PORT=3306
   DB_DATABASE=your_database_name
   DB_USERNAME=your_database_user
   DB_PASSWORD=your_database_password
   ```

### Step 3: File Upload

#### Option A: Using File Manager (cPanel/Plesk)
1. Compress your entire project into a ZIP file
2. Upload the ZIP file to your hosting account
3. Extract it in the root directory (usually `public_html` or `www`)
4. Move contents of `public` folder to your domain's document root
5. Update `index.php` to point to the correct paths

#### Option B: Using FTP/SFTP
1. Upload all files except the `public` folder to a directory above your document root
2. Upload contents of `public` folder to your document root (`public_html`)
3. Update `index.php` paths accordingly

#### Option C: Using SSH (if available)
```bash
# Upload and extract
scp qrover.zip user@yourserver.com:~/
ssh user@yourserver.com
unzip qrover.zip
mv qrover/* public_html/
```

### Step 4: Configure Document Root

Your hosting document root should contain:
- `index.php` (from Laravel's public folder)
- `assets/` folder
- `.htaccess` file

Update `index.php`:
```php
require __DIR__.'/../vendor/autoload.php';
$app = require_once __DIR__.'/../bootstrap/app.php';
```

### Step 5: Set Permissions

Set the following permissions:
```bash
chmod -R 755 storage/
chmod -R 755 bootstrap/cache/
chmod 644 .env
```

### Step 6: Run Database Migrations

#### Via SSH:
```bash
php artisan migrate --force
php artisan db:seed --class=VehicleCategorySeeder
php artisan db:seed --class=LocationSeeder
```

#### Via Web Interface:
Create a temporary migration script:
```php
<?php
// migrate.php - Place in document root, run once, then delete
require 'vendor/autoload.php';
$app = require_once 'bootstrap/app.php';
$kernel = $app->make(Illuminate\Contracts\Console\Kernel::class);
$kernel->call('migrate', ['--force' => true]);
echo "Migrations completed!";
```

### Step 7: Create Storage Link

#### Via SSH:
```bash
php artisan storage:link
```

#### Via File Manager:
Create a symbolic link from `public/storage` to `storage/app/public`

### Step 8: Final Configuration

1. **Update APP_URL in .env**
   ```env
   APP_URL=https://yourdomain.com
   ```

2. **Generate Application Key**
   ```bash
   php artisan key:generate
   ```

3. **Clear Caches**
   ```bash
   php artisan cache:clear
   php artisan config:clear
   ```

## 🔧 Shared Hosting Specific Configurations

### cPanel Configuration

1. **PHP Version**: Set to PHP 8.2+
2. **PHP Extensions**: Ensure these are enabled:
   - PDO
   - PDO_MySQL
   - OpenSSL
   - Mbstring
   - Tokenizer
   - XML
   - Ctype
   - JSON
   - BCMath
   - Fileinfo
   - GD

3. **Memory Limit**: Set to at least 256MB
4. **Max Execution Time**: Set to 300 seconds

### .htaccess Optimization

The included `.htaccess` file includes:
- Security headers
- Compression (Gzip)
- Browser caching
- URL rewriting
- Security restrictions

### Performance Optimization

1. **Enable OPcache** (if available)
2. **Use Redis/Memcached** (if available)
3. **Enable compression** in hosting control panel
4. **Set up CDN** for static assets

## 🛠️ Troubleshooting

### Common Issues

1. **500 Internal Server Error**
   - Check file permissions
   - Verify .env configuration
   - Check error logs in hosting control panel

2. **Database Connection Error**
   - Verify database credentials
   - Check database server hostname
   - Ensure database user has proper privileges

3. **Missing Storage Link**
   - Manually create symbolic link
   - Or copy files from storage/app/public to public/storage

4. **CSS/JS Not Loading**
   - Check asset paths in views
   - Verify .htaccess rules
   - Clear browser cache

### Log Files

Check these locations for error logs:
- `storage/logs/laravel.log`
- Hosting control panel error logs
- Server error logs (usually in logs/ or error_logs/)

## 📞 Support

For deployment assistance:
- **Email**: support@qrover.om
- **Documentation**: Check README.md for detailed information
- **Hosting Support**: Contact your hosting provider for server-specific issues

## 🔄 Updates and Maintenance

### Regular Maintenance
1. **Backup database** regularly
2. **Update dependencies** periodically
3. **Monitor error logs**
4. **Test functionality** after updates

### Updating the Application
1. Backup current installation
2. Upload new files
3. Run migrations: `php artisan migrate --force`
4. Clear caches: `php artisan cache:clear`
5. Test functionality

---

**Q ROVER** - Your luxury car rental system is now ready for production! 🚗✨
