# QuezCorp Medical: Automatic Browser Setup (Central Database)

**Use the browser setup wizard at `https://medical.quezcorp.com/install.php`.** This ZIP contains `public/install.php` and a **unique one-time access code**. The wizard sets up the central platform and first super administrator without manually editing `.env` or running migrations.

## 1. Prepare your hosting

- PHP **8.3 or newer**, MySQL **8+**, and necessary PHP extensions: PDO MySQL, OpenSSL, mbstring, XML, fileinfo, tokenizer and ctype.
- **Set the subdomain's document root to the project's `public/` directory**. Never expose the whole Laravel project to the web; `.env`, secrets and patient-related data must be outside the webroot. Use HTTPS with a valid certificate.
- Upload and extract the ZIP **outside the public webroot**, e.g. to a private folder containing the `public/` subfolder.
- Install Composer dependencies on the server in that project directory:

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

  The ZIP **does not include vendor/**. If your hosting has no Composer/terminal support, prepare `vendor/` on a matching PHP environment and upload it. The browser installer will show a preflight failure until `vendor/autoload.php` exists.
- Ensure the PHP process can write to `.env` (new file in project root), `storage/app/`, `storage/framework/` and `bootstrap/cache/`; configure least-privilege file ownership rather than world-writable permissions.

## 2. Prepare MySQL

In cPanel/MySQL Databases, create a **central database** (often prefixed, e.g. `account_quezcorp_platform`) and a **dedicated central MySQL user**. Give this user the necessary rights on the central database, including migrations. Record the exact host, port, database name, username and password.

You can instead check the **Try to create database** option in the wizard *only if the entered MySQL user is permitted to create databases*. The wizard does **not** create MySQL users/grants or clinic databases.

## 3. Run the browser wizard

1. On your local copy of the ZIP, open **`INSTALL-ACCESS-CODE.txt`**. The code is unique to this ZIP; keep it confidential. Its matching validator lives in `storage/app/installer.secret`, not under `public/`.
2. Visit **`https://medical.quezcorp.com/install.php`** (adjust domain for your server).
3. Confirm preflight checks are green; correct any missing requirements.
4. Enter the **one-time access code**, central MySQL details and the site URL.
5. Create a super-admin email and a **strong 14+ character password**.
6. Click **Install QuezCorp Medical**. The wizard connects to the central database, generates a random application key, writes `.env` with production settings, runs central Laravel migrations and creates the initial super-admin.
7. On success, visit `/admin/login` with those admin credentials.
8. **Delete `public/install.php` from the server**. Successful installation also writes `storage/app/medical-installed.lock`, removes the secret and rejects reruns even if the PHP installer file has not been removed.

For security, do not upload `INSTALL-ACCESS-CODE.txt` or the original ZIP to a web-accessible public folder. If you've leaked your setup code **before installation**, run `php scripts/rotate-installer-code.php` in the trusted terminal and use the newly generated code. Avoid making the installer public before you're ready to configure it.

## 4. Register your clinics

The installer creates **only the central database and your platform super-admin**. Each clinic needs a separate MySQL database, separate restricted MySQL credentials, and clinic registration using the CLI command described in `README.md`. That tenant isolation is intentional, to minimize access across clinics.

## After installation

- Keep `APP_DEBUG=false`, HTTPS on, and the `.env` and storage folders inaccessible from the web.
- Configure secure backup/encryption, tenant credential management, scheduled jobs and security monitoring.
- Perform real MySQL integration testing, tenant-isolation/access-control testing, and privacy/legal review before launch or any real patient data.
- This starter has **not** been run end-to-end on MySQL in the authoring environment. A successful wizard does not make it production-ready.
