# cPanel Deployment Guide for HealthCare Laravel Backend

## Quick Start - Option 1: Upload All Files

1. **Zip the entire project** (except mobile folder):
   ```bash
   # On Mac/Linux - exclude mobile apps and development files
   zip -r healthcare-backend.zip . -x "mobile/*" "node_modules/*" ".git/*" "*.DS_Store"
   ```

2. **Upload to cPanel**:
   - Login to cPanel → File Manager → public_html (or your subdomain)
   - Upload the zip file and extract it

3. **Install Dependencies on cPanel**:
   - Go to cPanel → Terminal (or SSH access)
   - Run: `composer install --no-dev --optimize-autoloader`

## Quick Start - Option 2: Pre-packaged (Recommended)

We've already installed vendor dependencies locally. You can:

1. **Create the package**:
   ```bash
   # Remove development-only files
   rm -rf node_modules mobile tests .zencoder .zenflow
   rm -f package.json package-lock.json phpunit.xml vite.config.js
   
   # Zip everything
   zip -r healthcare-backend.zip .
   ```

2. **Upload and configure**:
   - Extract in public_html
   - Set permissions:
     ```bash
     chmod -R 755 storage bootstrap/cache
     chmod -R 775 storage bootstrap/cache
     ```
   - Update `.env` with cPanel database credentials

---

## Step-by-Step cPanel Setup

### 1. Database Setup
- Login to cPanel → MySQL Databases
- Create a new database (e.g., `healthcare_db`)
- Create a database user with full privileges
- Import your local database:
  ```bash
  mysql -u username -p healthcare_db < database_dump.sql
  ```

### 2. Environment Configuration
Edit the `.env` file with cPanel database credentials:

```env
APP_NAME=HealthCare
APP_ENV=production
APP_DEBUG=false
APP_URL=https://yourdomain.com

DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=your_cpanel_db_name
DB_USERNAME=your_cpanel_db_user
DB_PASSWORD=your_db_password

SESSION_DRIVER=database
CACHE_DRIVER=file

# For Sanctum API tokens
SANCTUM_STATEFUL_DOMAINS=yourdomain.com
```

### 3. Required Terminal Commands
After uploading, run these in cPanel Terminal:

```bash
# Generate application key
php artisan key:generate

# Clear and optimize
php artisan config:clear
php artisan cache:clear
php artisan optimize

# Create storage link (if needed)
ln -s /home/username/public_html/storage/app/public /home/username/public_html/storage
```

### 4. Set Permissions
| Folder | Permission |
|--------|-------------|
| storage/ | 775 |
| bootstrap/cache/ | 775 |
| .env | 640 |

### 5. Configure PHP Version
- cPanel → MultiPHP Manager
- Select your domain
- Choose PHP 8.2+

---

## API Endpoints

Your Laravel API will be available at:
```
https://yourdomain.com/api/v1/health
```

### Available Routes:
| Method | Endpoint | Description |
|--------|----------|-------------|
| POST | /api/v1/login | User authentication |
| POST | /api/v1/logout | User logout |
| GET | /api/v1/patient/history | Get patient booking history |
| GET | /api/v1/patient/reports | Get patient reports |
| POST | /api/v1/appointments/book | Book appointment |
| POST | /api/v1/lab/book | Book lab test |
| POST | /api/v1/payments/initiate | Initiate payment |
| POST | /api/v1/payments/callback | Payment callback |
| PATCH | /api/v1/doctor/schedule | Update doctor schedule |
| GET | /api/v1/doctor/appointments | Get doctor appointments |

---

## Filament Admin Panel

Access the admin panel at:
```
https://yourdomain.com/admin
```

---

## Troubleshooting

### 500 Internal Server Error
- Check `.env` configuration
- Run: `php artisan config:cache`
- Check storage/logs/laravel.log

### Database Connection Error
- Verify database credentials in `.env`
- Ensure database user has privileges
- Check MySQL hostname (usually `localhost`)

### API Returns 401
- Ensure Sanctum is configured
- Check `SANCTUM_STATEFUL_DOMAINS` in .env

---

## Mobile App Configuration

Update your Flutter apps to point to your cPanel URL:

### Patient App
Edit: `mobile/patient_app/lib/core/constants/api_service.dart`
```dart
static const String baseUrl = 'https://yourdomain.com/api';
```

### Professional App
Edit: `mobile/professional_app/lib/core/constants/api_service.dart`
```dart
static const String baseUrl = 'https://yourdomain.com/api';
```

### Doctor App
Edit: `mobile/doctor_app/lib/core/constants/api_service.dart`
```dart
static const String baseUrl = 'https://yourdomain.com/api';
```
