# Deploy one school on cPanel (standalone mode)

This guide puts **one institution** (example: *Khan Anwar School* on
`khananwarschool.edu.bd`) on normal cPanel shared hosting. No VPS, no
subdomains, and nothing from the SaaS platform is needed.

Standalone mode is the same code as the SaaS version, with one setting in `.env`:

```
APP_MODE=standalone
```

With it on:

- The school website, admin panel, and teacher / student / parent portals all
  open on the school's own domain (`/`, `/login`, `/admin/...`).
- All features are on. There are no plans, trials, or student limits.
- The SaaS-only parts are switched off: marketing site, signup, pricing,
  Plan & Billing, Custom Domain, and tenant management.
- `/platform` is a small **System panel** for you, the vendor. It has Mail
  (SMTP), SSLCommerz, Maintenance mode, NCTB books and the Audit log.
- The mobile app API works on `https://<domain>/api/v1` and does not need the
  `X-Tenant` header.

---

## 0. What the hosting needs

| Need | Notes |
|---|---|
| **PHP 8.4 or newer** | The locked libraries (Symfony 8) need PHP ≥ 8.4.1. Set it in cPanel → *MultiPHP Manager* or *Select PHP Version*. |
| PHP extensions | `pdo_mysql`, `mbstring`, `openssl`, `tokenizer`, `xml`, `ctype`, `json`, `bcmath`, `curl`, `fileinfo`, `gd`, `intl`, `zip` |
| MySQL 8 / MariaDB 10.6+ | One database and one user |
| Cron jobs | Needed for queues and scheduled tasks |
| SSL | cPanel → *SSL/TLS Status* → AutoSSL (free) |
| Terminal (optional) | Makes steps 4–5 easier. Without it, use the "no Terminal" option in each step. |

Not available on shared hosting, and not needed in standalone mode: Redis,
Horizon, and Reverb. Real-time chat and notifications fall back to normal
page refresh.

---

## 1. Build the upload zip (on your computer)

```bash
git checkout standalong
scripts/standalone/build-release.sh
# → dist/corpo-edu-standalone-YYYYMMDD-HHMM.zip
```

The zip already contains `vendor/` (production only), the built CSS/JS
(`public/build`), and a `.env` with a fresh `APP_KEY`. The server does not
need Composer or Node.

## 2. Create the database (cPanel → MySQL® Databases)

1. Create a database, e.g. `cpuser_school`.
2. Create a user with a strong password, e.g. `cpuser_dbuser`.
3. *Add User To Database* → **ALL PRIVILEGES**.

## 3. Upload the files

Upload the project **outside** `public_html`. Only the `public/` folder should
be reachable from the web.

1. cPanel → *File Manager* → your home folder (`/home/cpuser/`).
2. Create a folder `khan-school`, upload the zip into it, then *Extract*.
3. Point the domain at `khan-school/public`. Pick one option:

**Option A: addon domain or subdomain (easiest).**
cPanel → *Domains* → the school's domain → *Manage* → set **Document Root** to
`khan-school/public`. Done.

**Option B: the account's main domain (document root fixed to `public_html`).**
Move everything **inside** `khan-school/public/` into `public_html/`,
including the hidden `.htaccess` file. Then replace `public_html/index.php`
with this:

```php
<?php

use Illuminate\Foundation\Application;
use Illuminate\Http\Request;

define('LARAVEL_START', microtime(true));

$base = __DIR__.'/../khan-school';

if (file_exists($maintenance = $base.'/storage/framework/maintenance.php')) {
    require $maintenance;
}

require $base.'/vendor/autoload.php';

/** @var Application $app */
$app = require_once $base.'/bootstrap/app.php';
$app->usePublicPath(__DIR__);

$app->handleRequest(Request::capture());
```

## 4. Edit `.env`

In File Manager, open `khan-school/.env`. Turn on *Show Hidden Files* in
Settings if you can't see it. Change the lines marked `CHANGE`:

```
APP_NAME="Khan Anwar School"
APP_URL=https://khananwarschool.edu.bd
APP_MODE=standalone
APP_MAIL_DOMAIN=khananwarschool.edu.bd

DB_DATABASE=cpuser_school
DB_USERNAME=cpuser_dbuser
DB_PASSWORD=********

MAIL_HOST=mail.khananwarschool.edu.bd
MAIL_USERNAME=noreply@khananwarschool.edu.bd
MAIL_PASSWORD=********
```

Leave `APP_KEY` as it is. It was generated for you, and changing it later
logs everyone out and breaks encrypted data.

## 5. Create the tables and the school

**With Terminal** (cPanel → *Terminal*):

```bash
cd ~/khan-school
php artisan migrate --force
php artisan school:install
```

The installer asks for the institution name and type (school, college,
university, madrasa, coaching, polytechnic, medical) and the admin login. It
can also create a System-panel login for you.

**Without Terminal:** prepare the database on your computer and import it.

```bash
scripts/standalone/export-database.sh khan_school_export
# runs all migrations + the installer on a NEW local database,
# then writes dist/khan_school_export.sql
```

Then use cPanel → *phpMyAdmin* → select `cpuser_school` → *Import* → that `.sql`
file.

## 6. Public storage link (uploaded logos, photos, documents)

Uploaded files live in `storage/app/public` and must be visible at `/storage`.

- **Terminal, Option A:** `cd ~/khan-school && php artisan storage:link`
- **Terminal, Option B:** `ln -s ~/khan-school/storage/app/public ~/public_html/storage`
- **No Terminal:** add a one-time cron job (step 7) with the `ln -s` command
  above (use full paths, e.g. `/home/cpuser/...`). Let it run once, then delete it.

## 7. Cron jobs (cPanel → Cron Jobs)

Add both, set to **every minute** (`* * * * *`). Replace `cpuser` with your
account user. If `php` is not found, use the full path shown in *MultiPHP
Manager*, e.g. `/opt/cpanel/ea-php84/root/usr/bin/php`.

```
cd /home/cpuser/khan-school && php artisan schedule:run >> /dev/null 2>&1
cd /home/cpuser/khan-school && php artisan queue:work --stop-when-empty --max-time=55 >> /dev/null 2>&1
```

The first runs scheduled tasks: report emails, CMS publishing, monthly
coaching fees. The second sends queued email/SMS and other background jobs.

## 8. Speed it up (optional, needs Terminal)

```bash
cd ~/khan-school
php artisan optimize        # caches config, routes, views
```

Run `php artisan optimize:clear` after you edit `.env` or upload new code.

## 9. Check it works

| URL | Expect |
|---|---|
| `https://khananwarschool.edu.bd/` | School website |
| `https://khananwarschool.edu.bd/login` | Login for admin, teachers, students and parents |
| `https://khananwarschool.edu.bd/admin/dashboard` | Admin dashboard (after login) |
| `https://khananwarschool.edu.bd/platform/login` | System panel (vendor) |
| `https://khananwarschool.edu.bd/api/v1/health` | `{"status":"ok"...}` for the mobile app |

Then, in the System panel, set **Mail (SMTP)** and **SSLCommerz** (for
online fee payment). In the school admin, set up **Branding**, the
**Website** pages, **Academic Sessions** and **Classes**.

If you see *"This site is not set up yet"*, the database has no institution.
Do step 5.

---

## Updating to a new version

1. Build a new zip (step 1).
2. Upload and extract it over `khan-school/`, but **keep the server's `.env`
   and `storage/` folder**. The zip's `storage/` folder holds only empty
   placeholder folders. Don't let it replace the server's `storage/app`.
3. Run `php artisan migrate --force && php artisan optimize`. Without
   Terminal, run it once from a temporary cron job.

## Backups

- cPanel → *Backup* → download the MySQL database regularly.
- Also back up `khan-school/storage/app` (uploaded files) and `.env`.

## Moving to SaaS later

The `saas` branch is the multi-tenant version (VPS, wildcard subdomains,
signup, plans). The database structure is the same, so a standalone school
can later be moved into the SaaS platform as one of its tenants.
