# MotoSolution Bangladesh – cPanel Production Deployment Guide

This guide walks you through deploying the **MotoSolution Bangladesh** platform to any standard cPanel web hosting environment (e.g., Namecheap, Hostinger, Bluehost, cPanel VPS).

---

## Architecture Overview on cPanel

For security, **never** put the entire Laravel app directly inside `public_html`. The best practice on cPanel is:

```text
/home/your_username/
├── motosolution/               <-- Main Laravel core (outside public_html)
│   ├── app/
│   ├── bootstrap/
│   ├── config/
│   ├── database/
│   ├── lang/
│   ├── resources/
│   ├── routes/
│   ├── storage/
│   ├── vendor/
│   ├── .env                    <-- Production environment secrets
│   └── artisan
│
└── public_html/                <-- Only contents of Laravel's 'public/' folder
    ├── build/                  <-- Compiled Vite CSS & JS assets
    ├── index.php               <-- Web entry point (updated paths)
    ├── .htaccess               <-- URL routing rules
    ├── robots.txt
    └── storage/                <-- Symlink to ../motosolution/storage/app/public
```

---

## Step 1: Pre-Deployment Build (On Your Computer)

Before uploading to cPanel, compile the frontend assets and prepare dependencies:

```bash
# 1. Compile CSS and JavaScript assets with Vite
npm run build

# 2. Install optimized PHP dependencies without dev packages
composer install --optimize-autoloader --no-dev
```

### Create the Deployment ZIP:
Zip the project files, **excluding** `node_modules`, `.git`, and test cache.
You can run this in your terminal:
```bash
zip -r motosolution-deploy.zip . \
  -x "node_modules/*" \
  -x ".git/*" \
  -x "storage/logs/*.log" \
  -x ".phpunit.result.cache" \
  -x ".gemini/*"
```

---

## Step 2: Configure PHP Version on cPanel

1. Log in to your **cPanel** dashboard.
2. Under the **Software** section, open **Select PHP Version** or **MultiPHP Manager**.
3. Choose **PHP 8.2** or **PHP 8.3**.
4. Enable the following PHP extensions (under **Extensions**):
   - `pdo_mysql`
   - `mbstring`
   - `openssl`
   - `bcmath`
   - `curl`
   - `fileinfo`
   - `xml`
   - `zip`
   - `gd`
   - `intl`

---

## Step 3: Create MySQL Database in cPanel

1. In cPanel, click **MySQL Database Wizard**.
2. **Step 1 - Create Database**: e.g., `youruser_motosol`
3. **Step 2 - Create Database User**: e.g., `youruser_dbuser` with a strong password.
4. **Step 3 - Add User to Database**: Check **ALL PRIVILEGES** and click **Make Changes**.
5. Save the Database Name, Username, and Password for your `.env` configuration.

---

## Step 4: Upload & Organize Files in cPanel

### Method A: Main Domain (`public_html`)

1. Open **cPanel File Manager**.
2. In your home root directory (`/home/your_username/`), create a new folder named `motosolution`.
3. Upload `motosolution-deploy.zip` into `/home/your_username/motosolution/` and click **Extract**.
4. Move the contents of `/home/your_username/motosolution/public/`:
   - Select all files and folders inside `motosolution/public/` (`build`, `favicon.ico`, `index.php`, `.htaccess`, etc.).
   - Move them directly into `/home/your_username/public_html/`.
5. Edit `/home/your_username/public_html/index.php`:
   Update lines 18-35 to point to your `motosolution` directory:
   ```php
   // Determine if the application is in maintenance mode...
   if (file_exists($maintenance = __DIR__.'/../motosolution/storage/framework/maintenance.php')) {
       require $maintenance;
   }

   // Register the Composer autoloader...
   require __DIR__.'/../motosolution/vendor/autoload.php';

   // Bootstrap Laravel and handle the request...
   (require_once __DIR__.'/../motosolution/bootstrap/app.php')
       ->handleRequest(Request::capture());
   ```

### Method B: Subdomain or Addon Domain (Easiest)

If you are using a subdomain (e.g., `app.motosolbd.com`) or an Addon Domain:
1. In cPanel, go to **Domains**.
2. Click **Create A New Domain** or edit your existing domain.
3. Change the **Document Root** directly to:
   `/home/your_username/motosolution/public`
4. This removes the need to move any files or change `index.php`.

---

## Step 5: Configure `.env` Production Settings

In `/home/your_username/motosolution/`:
1. If `.env` is hidden, click **Settings** (top-right of File Manager) and check **Show Hidden Files (dotfiles)**.
2. Edit `.env` and set:

```ini
APP_NAME="MotoSolution Bangladesh"
APP_ENV=production
APP_KEY=base64:... # (Keep your generated key)
APP_DEBUG=false
APP_URL=https://motosolbd.com

LOG_CHANNEL=daily
LOG_LEVEL=error

# Database Configuration (MySQL)
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=youruser_motosol
DB_USERNAME=youruser_dbuser
DB_PASSWORD=YourSecurePasswordHere

# Session & Cache
BROADCAST_CONNECTION=log
CACHE_STORE=file
QUEUE_CONNECTION=database
SESSION_DRIVER=file
SESSION_LIFETIME=120

# Japanese Auction Provider ('mock' for testing, 'generic_api' for live Japanese feed)
JAPAN_AUCTION_PROVIDER=mock

# Showroom Details
SHOWROOM_PHONE="+8801714116695"
WHATSAPP_NUMBER="8801404066329"
SHOWROOM_EMAIL="info@motosolbd.com"
```

---

## Step 6: Database Migration & Storage Link

### Option 1: Via cPanel Terminal (Recommended)
If your cPanel hosting includes the **Terminal** tool:
1. Click **Terminal** in cPanel.
2. Run:
```bash
cd ~/motosolution

# 1. Run migrations and seed the initial dataset
php artisan migrate --seed --force

# 2. Create public storage link for vehicle images
php artisan storage:link

# 3. Cache configuration, routes, and views for lightning-fast performance
php artisan config:cache
php artisan route:cache
php artisan view:cache
```

### Option 2: Without cPanel Terminal (phpMyAdmin)
If your hosting does not have SSH/Terminal access:
1. In your local development machine, run:
   ```bash
   php artisan migrate:generate # or export database from phpMyAdmin / SQLite
   ```
2. Open **phpMyAdmin** in cPanel.
3. Select your database (`youruser_motosol`) and click **Import** to upload the `.sql` dump.
4. To create the storage link without SSH, you can add a temporary route in `routes/web.php`:
   ```php
   Route::get('/run-artisan-storage-link', function () {
       \Artisan::call('storage:link');
       \Artisan::call('config:cache');
       \Artisan::call('route:cache');
       \Artisan::call('view:cache');
       return 'Artisan commands completed!';
   });
   ```
   Visit `https://motosolbd.com/run-artisan-storage-link` once in your browser, then delete this route from `routes/web.php`.

---

## Step 7: Setup cPanel Cron Job (Auction & Tracking Automation)

The MotoSolution platform automates Japanese live auction timers, bidding expiry, and tracking notifications using Laravel's task scheduler.

1. In cPanel, go to **Cron Jobs**.
2. Under **Add New Cron Job**:
   - Select **Once Per Minute** (`* * * * *`).
   - In the **Command** field, enter:
   ```bash
   /usr/local/bin/php /home/your_username/motosolution/artisan schedule:run >> /dev/null 2>&1
   ```
   *(Replace `/usr/local/bin/php` with your server's PHP path, and `your_username` with your cPanel username).*

---

## Step 8: Permissions & SSL Certificate

1. **File Permissions**:
   - Folders: `755`
   - Files: `644`
   - In File Manager, ensure `motosolution/storage` and `motosolution/bootstrap/cache` are set to `775` or `755` so Laravel can write cache and logs.
2. **Install SSL Certificate**:
   - In cPanel, open **Let's Encrypt SSL** or **SSL/TLS Status**.
   - Click **Run AutoSSL** on your domain to enable HTTPS encryption.

---

## Default Admin & Customer Credentials

Once seeded, you can log in to the admin CRM:
- **Admin CRM URL**: `https://motosolbd.com/admin/dashboard`
- **Super Admin**: `admin@motosolbd.com` / `password123`
- **Auction Desk**: `auction@motosolbd.com` / `password123`
- **Sales Desk**: `sales@motosolbd.com` / `password123`
- **Customer Portal**: `tanvir@gmail.com` / `password123`
