# Laravel Hub API cPanel Deployment Plan

This implementation plan details the steps required to deploy the Laravel Hub API backend onto your cPanel hosting at `hub.ditech.website`. It covers subdomain setup, file management, configuration, and the two options for running database migrations.

## User Review Required

> [!IMPORTANT]
> **Subdomain Separation**: Do not extract the Laravel Hub API files into the root of `wendys.ditech.website`. That domain is reserved for the Next.js Bakery Storefront. You must create a new subdomain (e.g., `hub.ditech.website` or `api.ditech.website`) specifically for the Laravel backend.

> [!WARNING]
> **Document Root Configuration**: Laravel requires its document root to point to the `public/` directory (e.g., `/home/username/hub.ditech.website/public`). Pointing it to the root project folder will expose sensitive files like your `.env` configuration.

## Proposed Changes

No changes to the local workspace codebase are required for this deployment, as the deployment package (`hub_cpanel_deploy.zip`) has already been generated. 

However, if you choose **Method B (Programmatic Migration Route)** to run migrations, we will need to temporarily modify the backend routes.

### API Routing (For Programmatic Migrations)

#### [MODIFY] [api.php](file:///c:/Users/diTech/Documents/vvvv/hub/routes/api.php)
Add a temporary, secured endpoint at the bottom of the API routes file to trigger migrations through a web browser.

```php
// Temporary migration route - REMOVE AFTER USE
Route::get('/run-migrations', function () {
    // Basic protection using a query parameter key
    if (request()->query('key') !== 'ditech_secure_migrate_2026') {
        abort(403, 'Unauthorized');
    }
    
    \Illuminate\Support\Facades\Artisan::call('migrate --force');
    return "Database migrated successfully! Output:<br><pre>" . \Illuminate\Support\Facades\Artisan::output() . "</pre>";
});
```

---

## Deployment & Setup Guide

### Step 1: Subdomain Configuration in cPanel
1. Log in to your **cPanel Dashboard**.
2. Find the **Domains** or **Subdomains** tool.
3. Create a new subdomain:
   - **Subdomain Name**: `hub` (resulting in `hub.ditech.website`).
   - **Document Root**: `/home/username/hub.ditech.website/public` (Ensure it ends in `/public`).

### Step 2: File Upload & Extraction
1. Open the cPanel **File Manager**.
2. Navigate to the newly created folder `/home/username/hub.ditech.website/` (one level above `/public`).
3. Click **Upload** and upload `C:\Users\diTech\Documents\vvvv\hub_cpanel_deploy.zip`.
4. Once uploaded, right-click the zip file and choose **Extract**.

### Step 3: Environment Setup
1. Inside the file manager, locate the `.env.example` file in the root of your extracted files.
2. Rename the file to `.env`.
3. Open the file in the cPanel Editor and update the following settings:
   ```env
   APP_ENV=production
   APP_DEBUG=false
   APP_URL=https://hub.ditech.website

   # Database Settings (Update with your cPanel MySQL details)
   DB_CONNECTION=mysql
   DB_HOST=127.0.0.1
   DB_PORT=3306
   DB_DATABASE=your_database_name
   DB_USERNAME=your_database_user
   DB_PASSWORD=your_database_password
   ```
4. Save and close the editor.

### Step 4: Choose Database Migration Method

Select **one** of the two methods below to run your database migrations.

#### Option A: cPanel Terminal (Recommended)
Use this option if your hosting plan includes SSH or cPanel Terminal access.
1. Open the **Terminal** tool in cPanel.
2. Navigate to your hub directory:
   ```bash
   cd hub.ditech.website
   ```
3. Run the migrations:
   ```bash
   php artisan migrate --force
   ```

#### Option B: Programmatic Web Route
Use this option if you do not have Terminal/SSH access in cPanel.
1. Open `/routes/api.php` in the cPanel File Manager Editor.
2. Append the temporary migration route provided in the **Proposed Changes** section above.
3. In your web browser, navigate to:
   `https://hub.ditech.website/api/run-migrations?key=ditech_secure_migrate_2026`
4. Once you see the success message, edit `/routes/api.php` again and **delete the temporary route code** to secure your backend.

---

## Verification Plan

### Manual Verification
- Navigate to `https://hub.ditech.website` in your browser. You should see a default Laravel landing page or a `404 Not Found`/`JSON Response` (indicating the server is running, but no index page is defined for API routes).
- Navigate to `https://hub.ditech.website/api/user` (or any other public API endpoint) to check that the routing engine works and returns a JSON response instead of a web server error.
- Check your cPanel MySQL Database to verify that the tables (e.g. `users`, `products`, `orders`) have been created successfully.
