# Chillcore Field Service Manager — cPanel / WHM / LiteSpeed deployment

This package contains the Laravel application source, migrations, feature tests, built CSS/JavaScript assets and configuration. Use a staging subdomain and a new database for the first installation. The application requires PHP 8.3 or later (64-bit), Composer 2, MySQL 8 or MariaDB supported by Laravel 13, and HTTPS.

## 1. Prepare PHP and the domain in WHM/cPanel

1. In WHM, use **EasyApache 4** to install a PHP version compatible with the domain, then enable PHP 8.3+ and these extensions for both the web SAPI and CLI: `bcmath`, `ctype`, `curl`, `dom`, `fileinfo`, `filter`, `gd`, `hash`, `iconv`, `intl`, `mbstring`, `openssl`, `pcre`, `PDO`, `pdo_mysql`, `session`, `tokenizer`, `xml`, and `zip`.
2. In cPanel **MultiPHP Manager**, select the same PHP version for the service subdomain. In **LiteSpeed Web Cache Manager** or the hosting control panel, confirm the domain is handled by LiteSpeed and uses the PHP LSAPI handler for that version. In Terminal, confirm `php -v`, `php -m`, and `composer --version`.
3. Create a subdomain such as `service.chillcore.co.uk`. Set its document root to the application's `public` directory. The recommended layout is `/home/CPANELUSER/chillcore/public`, with the full application at `/home/CPANELUSER/chillcore`. Keep `.env`, `vendor`, `storage`, source code and database backups outside any web-accessible directory. Do not point the domain at the project root.
4. Enable AutoSSL and confirm that `https://service.chillcore.co.uk` loads before enabling browser location sharing.

## 2. Create the MySQL database

In cPanel **MySQL® Database Wizard**, create a database and a dedicated database user. Grant that user all privileges on this database. cPanel often prefixes both names, for example `account_chillcore`. Use the exact prefixed names in `.env`; the database host is commonly `localhost` on cPanel.

## 3. Upload and configure the application

1. Upload `Chillcore_Field_Service_Manager_Production.zip` using cPanel File Manager or SFTP. Extract it into `/home/CPANELUSER/chillcore`, outside `public_html`. The extracted project root contains `artisan`, `composer.json` and `public/`.
2. Open cPanel Terminal or SSH as the cPanel account and change to the project root. Copy `.env.example` to `.env` and edit it:

   ```bash
   cd ~/chillcore
   cp .env.example .env
   ```

   Set `APP_URL` to the HTTPS service URL; use `APP_ENV=production`, `APP_DEBUG=false`, `APP_TIMEZONE=Europe/London`, `DB_CONNECTION=mysql`, and the database values from step 2. Keep `SESSION_SECURE_COOKIE=true`. Configure mail and payment credentials as described below. Do not put real credentials in the ZIP or commit `.env` to source control.

3. Install production dependencies with the same PHP version selected for the site:

   ```bash
   composer install --no-dev --optimize-autoloader --prefer-dist
   ```

   The package does not contain `vendor/`. On the first install Composer resolves the declared versions and creates `composer.lock`; retain that lockfile for subsequent deployments. If Composer is not on `PATH`, use the Composer 2 executable supplied by your host. Do not run Composer as root.

4. Generate the application encryption key and apply the database migrations:

   ```bash
   php artisan key:generate --force
   php artisan migrate --force
   php artisan config:cache
   php artisan route:cache
   php artisan view:cache
   ```

5. Create the first administrator. The command prompts for a password and requires at least 12 characters:

   ```bash
   php artisan chillcore:admin admin@chillcore.co.uk
   ```

6. Make the application storage and framework cache writable by the cPanel account that runs PHP. Keep restrictive permissions; do not use `777`:

   ```bash
   chmod 600 .env
   chmod -R u+rwX,g+rX storage bootstrap/cache
   ```

   The web process must be able to write to `storage/app/private`, `storage/framework`, `storage/logs` and `bootstrap/cache`. Photos and database backups are stored under private storage, outside `public/`.

## 4. Configure email and online card payments

### SMTP email

Set `MAIL_MAILER=smtp`, `MAIL_HOST`, `MAIL_PORT`, `MAIL_USERNAME`, `MAIL_PASSWORD`, `MAIL_SCHEME` (normally `smtp` on port 587 with STARTTLS, or `smtps` on port 465), `MAIL_FROM_ADDRESS` and `MAIL_FROM_NAME`. Use the SMTP credentials issued by your email provider. The example uses the `log` mailer until configured; log mode does not deliver customer emails. Test booking acknowledgement, dispatch notification, engineer message notification and document delivery from staging.

### Stripe Checkout

Online card payment is optional until configured. From the Stripe account's test environment, add these server-only values to `.env`:

- `STRIPE_SECRET=sk_test_...` (use `sk_live_...` only after test payments and reconciliation pass)
- `STRIPE_WEBHOOK_SECRET=whsec_...`

Add a Stripe webhook endpoint at `https://service.chillcore.co.uk/stripe/webhook` and subscribe to `checkout.session.completed`. Copy that endpoint's signing secret to `STRIPE_WEBHOOK_SECRET`. Keep both secrets private; never place them in a Blade view, JavaScript, email, or this archive. The app creates GBP card Checkout sessions and records a payment only after validating the signed webhook. Confirm success, cancellation, duplicate webhook delivery and partial/full payment reconciliation in Stripe test mode before live use. Without these values, secure card checkout returns an explanatory unavailable response; customers can still use your existing offline payment process.

### Maps and location

Leaflet and OpenStreetMap tiles are loaded by the browser from their public HTTPS endpoints. No map key is included or required for the sample map. This requires outgoing internet access from the user's browser. For a commercial service, review the current tile provider's terms and capacity limits; switch to an appropriate hosted tile provider if usage requires it. Engineer location sharing requires HTTPS, device permission, an open dashboard in the engineer's browser and a working connection. Sharing is started and stopped explicitly; the map only displays recent reports (up to two hours) and location history is pruned after 30 days.

## 5. Start the scheduler for automatic dispatch, maintenance and backups

In cPanel **Cron Jobs**, add this command to run every minute. Use the actual absolute PHP path shown by your host's `which php` and the actual cPanel username:

```cron
* * * * * /usr/local/bin/php /home/CPANELUSER/chillcore/artisan schedule:run >> /home/CPANELUSER/chillcore/storage/logs/scheduler.log 2>&1
```

The Laravel scheduler runs automatic assignment every 10 minutes, due maintenance job creation daily at 06:00 Europe/London, compressed MySQL backups daily at 02:00, and location history cleanup daily. Verify the cron by checking `storage/logs/laravel.log` and `storage/logs/scheduler.log`; then run these commands manually once in staging:

```bash
php artisan chillcore:dispatch
php artisan chillcore:recurring
php artisan chillcore:backup
```

Automatic dispatch assigns eligible unassigned online/recurring jobs to the engineer with the lightest job count on the scheduled day. It does not yet calculate travel time, engineer skills, holidays, leave or working hours; review each dispatch and schedule during the pilot. Backups use `mysqldump`, are gzip-compressed under `storage/app/private/backups`, receive owner-only file permissions and are pruned after `BACKUP_RETENTION_DAYS` (default 30). Verify `mysqldump` is installed and available to the cron environment. Keep independent off-server backups and periodically rehearse a restore; an on-server backup does not protect against account or disk loss.

To restore a selected backup to a staging database, decompress it and import using credentials provided interactively by the host's MySQL client. Verify the target database name carefully before importing; a restore replaces database contents. Restore private job photos separately from a file backup.

## 6. First administrator setup

Sign in at `/login`. Add customer, engineer and staff user records. Add checklist templates with one task per line; engineers can adapt the checklist and tick each item on a job. Configure online booking under **Booking settings** and make sure at least one administrator exists to receive booking notifications. Link customer portal users to their customer record using `customers.user_id` where customer sign-in is required. Create recurring maintenance plans with a customer, interval and next due date. Create a quotation or invoice, review its PDF, then use the customer link or email button to share it. Payment records can be entered manually when offline payments are received.

The generated ventilation document records measured values and checks for the work order. It is not presented as a building-control certificate and does not replace any required notification, competent-person scheme process, design record or project-specific compliance check.

## 7. Upgrades and recovery

Before every release, take a database and files backup. Upload the new source outside the web root, preserve the live `.env` and private photo files, then run:

```bash
composer install --no-dev --optimize-autoloader --prefer-dist
php artisan down
php artisan migrate --force
php artisan optimize:clear
php artisan config:cache
php artisan route:cache
php artisan view:cache
php artisan up
```

If an upgrade fails, put the site in maintenance mode, restore the previous application files and database backup, then clear Laravel caches. Do not restore a production database over the wrong cPanel database.

## 8. Validation and deployment-specific checks

The package includes PHPUnit feature tests in `tests/Feature`. To run them in a development or staging copy, install development dependencies and run:

```bash
composer install
php artisan test
php artisan route:list
php artisan migrate:status
```

Before go-live, test with separate administrator, engineer and customer accounts: permission-denied requests; create/edit/search/delete flows; linked-record deletion; booking date-window validation; engineer dispatch; location start/stop and stale map markers; call links on an actual handset; custom checklist ticks; signature and photo upload; both PDF downloads; Part F measurement review; quote acceptance; email attachments; Stripe webhook signature/replay handling; partial and full payment totals; recurrence; scheduled cPanel tasks; backup creation, permissions and restore; HTTPS redirects; session expiry; and mobile layout. Test with the production PHP handler, MySQL/MariaDB version, LiteSpeed rules, SMTP provider, Stripe test mode, browser geolocation and tile provider.

This archive is source-complete but the build workspace had no PHP CLI, Composer or MySQL server available. As a result, `composer install`, Laravel boot, migrations and PHPUnit could not be executed here. Run the commands above in staging before using live customer data or accepting payments.
