# Deployment Guide — ESL Price Tag Demo Scheduling Portal

This guide covers deploying **Module 1 (application skeleton)** on a
**CyberPanel** server. Each later module will append any additional
deployment steps it introduces (e.g. cron jobs from Module 7).

## 1. Requirements

- CyberPanel with PHP 8.2 (LiteSpeed or Apache)
- MySQL / MariaDB database
- Composer installed on the server (or run locally and upload `vendor/`)
- SSL certificate (recommended — enable AutoSSL in CyberPanel)

## 2. Create the website in CyberPanel

1. CyberPanel → **Websites → Create Website**
2. Choose your domain/subdomain (e.g. `booking.yourdomain.com`)
3. Select **PHP 8.2** as the PHP version for this vHost.
4. After creation, go to **Websites → List Websites → Manage → vHost Conf / File Manager**.

## 3. Set the correct Document Root

CyberPanel by default points the document root at the domain's root
folder. This application's **actual web root is the `public/` folder**.

- Go to **Websites → List Websites → [your domain] → Manage**
- Under **Basic/vHost settings**, change the **Document Root** to:
  `/home/<domain>/public_html/public`

(A root-level `.htaccess` safeguard is also included in case this step
is skipped, but setting the Document Root correctly is the proper,
supported approach and avoids exposing `.env`, `database/`, etc.)

## 4. Upload the application files

Upload the entire project (excluding `vendor/`, which Composer will
generate) to `/home/<domain>/public_html/` via SFTP or the CyberPanel
File Manager, so that the structure looks like:

```
/home/<domain>/public_html/
├── app/
├── config/
├── database/
├── public/          <-- Document Root points here
├── storage/
├── composer.json
├── .env.example
└── ...
```

## 5. Install PHP dependencies

Via SSH:

```bash
cd /home/<domain>/public_html
composer install --no-dev --optimize-autoloader
```

This downloads PHPMailer and phpdotenv into `vendor/`. No custom coding
is required — this is a standard dependency installation step.

## 6. Configure environment variables

```bash
cp .env.example .env
nano .env
```

Fill in:
- `APP_URL` — the full HTTPS URL of the site
- `APP_KEY` — any random 64-character string (used for future
  encryption/signing needs)
- `DB_*` — the MySQL database credentials (create the database and a
  dedicated MySQL user via CyberPanel → **Databases**)
- `MAIL_*` — SMTP credentials PHPMailer will use to send booking
  confirmation/reminder emails (Module 4 onward)

## 7. Create the database and import the schema

1. CyberPanel → **Databases → Create Database** (note DB name, user, password — put them in `.env`)
2. Import the schema:

```bash
mysql -u <db_user> -p <db_name> < database/schema.sql
```

Or via phpMyAdmin (CyberPanel → Databases → phpMyAdmin): open the
database, go to **Import**, and select `database/schema.sql`.

This creates all tables for the entire application (bookings, admin
users, settings, business hours, email templates/logs, activity logs)
and seeds safe default settings. **No admin login is created yet** —
that is done securely in Module 2 via a CLI command.

## 8. Set folder permissions

```bash
chmod -R 755 /home/<domain>/public_html
chmod -R 775 /home/<domain>/public_html/storage
```

Ensure the web server user (usually the CyberPanel-created system user
for the domain) owns the `storage/` directory so error logs can be
written.

## 9. Verify

Visit `https://booking.yourdomain.com/` — you should see the landing
page describing the ESL Tag demo, styled with Bootstrap 5.

If you see a 500 error, check:
- `storage/logs/php_errors.log`
- That `.env` exists and all required keys are filled in
- That the database credentials are correct and the schema was imported

---

*This guide will be extended in later modules (admin login setup,
cron job for reminder emails, SMTP verification, etc.).*
