# WACLOUD Platform — Deployment Guide (cPanel)

This package is a complete PHP 8 / MySQL application. It has no Composer dependencies, so it runs on standard cPanel shared hosting, a VPS or a cloud server.

## 1. Server requirements
- PHP **8.1+** with extensions: `pdo_mysql`, `curl`, `openssl`, `mbstring`, `fileinfo`, `zlib`, `json`
- MySQL 5.7+ / MariaDB 10.3+
- Apache with `mod_rewrite` (default on cPanel) or Nginx (see §10)
- An SSL certificate (cPanel AutoSSL / Let's Encrypt is fine)
- Cron access

## 2. Upload
The zip contains two folders:

```
wacloud/        -> upload to /home/CPANELUSER/wacloud   (OUTSIDE the web root)
public_html/    -> upload contents into /home/CPANELUSER/public_html
```
`public_html/index.php` finds the application in `../wacloud/app` automatically. Nothing sensitive (config, uploads, logs, backups) is web-accessible.

Set permissions: `wacloud/storage` and its sub-folders writable by PHP (755/750), and `public_html/uploads` writable (create it if missing).

## 3. Database
cPanel → MySQL Databases: create a database and user, grant ALL PRIVILEGES. Use `utf8mb4`.

## 4. Configuration
```
cp wacloud/app/config.sample.php wacloud/app/config.php
```
Edit `config.php`:
- `app.url` = `https://www.waclouds.com`, `app.env` = `production`, `app.key` = output of `php -r "echo bin2hex(random_bytes(32));"`
- `db.*` — the database from step 3
- `mail.*` — an SMTP mailbox on your domain (e.g. `no-reply@waclouds.com`, host `mail.waclouds.com`, port 465 `ssl`). Set `sales_email`, `support_email`, `finance_email` to real team inboxes.
- Integrations (each is optional and can be enabled later): see §6.

## 5. Install
Visit `https://www.waclouds.com/install`, enter the Super Administrator details and click **Install**. (Or via SSH: `php wacloud/database/install.php "Name" admin@waclouds.com 'StrongPassword'`.)

The installer creates the tables and loads the service catalogue, all packages (website, SEO, maintenance, digital presence, hosting, ERP, AI training, managed IT), 12 industry pages, 11 sector ERP solutions, 15 ERP modules, 10 AI Academy programmes, 12 domain extensions, 60+ notification templates, legal pages and FAQs. It then writes `storage/install.lock`, which disables the installer permanently.

> **Before launch, review every price** under *Admin → Packages & Pricing* and *Domains → Extensions & pricing*. The installer loads reasonable starting prices only. Also have a lawyer review the Privacy Policy and Terms (*Admin → Website Content → Pages*).

## 6. Integrations

### 6.1 WHMCS (hosting, domains, billing engine)
1. WHMCS → *Setup → Staff Management → Manage API Credentials* → create an **API Role** permitting at least: `AddClient, GetClients, GetClientsDetails, UpdateClient, GetCurrencies, GetProducts, AddOrder, AcceptOrder, GetInvoice, GetInvoices, UpdateInvoice, AddInvoicePayment, GetClientsProducts, GetClientsDomains, UpdateClientDomain, DomainWhois, GetTLDPricing, DomainGetNameservers, DomainUpdateNameservers, DomainGetLockingStatus, DomainUpdateLockingStatus, DomainRequestEPP, AddContact, CreateSsoToken, OpenTicket, AddTicketReply, GetTickets, GetStats, GetHealthStatus`.
2. Create API credentials for an admin user with that role. Put `identifier` and `secret` in `config.php` → `whmcs`, set `enabled => true` and `url`.
3. WHMCS → *General Settings → Security → API IP Access Restriction*: add your web server's IP.
4. `payment_method` must be the system name of an **active** WHMCS gateway (e.g. `banktransfer`). WACLOUD collects the money (MoMo/Airtel/Pesapal/bank) and records it in WHMCS with `AddInvoicePayment`, which triggers WHMCS automation.
5. WHMCS automation settings:
   - *Products*: set **Auto Setup → "Automatically setup the product as soon as the first payment is received"** with your server module (cPanel/WHM, Plesk, DirectAdmin…).
   - *Domains → Domain Registrars*: activate your registrar module(s). For **.ug / .co.ug / .or.ug / .ac.ug / .sc.ug**, use an accredited .ug registrar or reseller that provides a WHMCS registrar module.
   - *General Settings → Domains*: enable **"Auto Register Domains on Payment"**, renewal notices, and **Domain Pricing** for each TLD.
   - *Automation Settings*: enable WHMCS cron, auto-suspension/unsuspension, invoice reminders, domain expiry reminders.
6. In WACLOUD Admin:
   - *WHMCS Hosting* → confirm "Connected".
   - *Domains → Extensions & pricing → Sync from WHMCS* to import the registrar-supported TLD list (unsupported extensions are hidden automatically). Then set WACLOUD selling prices/promos; these are written onto the WHMCS invoice and the domain's recurring amount at checkout.
   - *Packages & Pricing*: for each hosting/email/SSL package choose the matching **WHMCS product**.
   - *Settings → Domains & bundles*: confirm bundle package slugs and default nameservers.

**Behaviour:** hosting and domain orders are created in WHMCS as unpaid orders; registration and provisioning only happen after payment is verified. A domain is shown as *Registered* only after WHMCS reports it `Active` (checked every 5 minutes by cron). Failed registrations alert Finance for refund/credit.

**Single sign-on:** "Manage", "Manage DNS", "Upgrade" buttons use `CreateSsoToken`, so clients move into WHMCS pages without logging in again. For a seamless look, apply a WHMCS client-area theme in WACLOUD colours (deep blue `#0a2a5e`, sky blue `#38b6ff`, orange `#f7931e`) and host WHMCS on `billing.waclouds.com`.

### 6.2 MTN Mobile Money (Collections)
1. Register at momodeveloper.mtn.com, subscribe to **Collections**, test in sandbox (`base_url` sandbox, `environment` `sandbox`, `currency` `EUR`).
2. Apply for go-live with MTN Uganda. You receive a production subscription key, API user and API key. Set `environment` to `mtnuganda`, `currency` `UGX`.
3. Callback URL (send to MTN when going live): `https://www.waclouds.com/webhooks/mtn`.

### 6.3 Airtel Money (Collections)
1. Register at developers.airtel.africa, create an application with **Collection** product (staging first).
2. Configure callback URL `https://www.waclouds.com/webhooks/airtel`; if you enable callback authentication, put the shared secret in `airtel.callback_secret`.
3. Go-live with Airtel Uganda; set `base_url` to production.

### 6.4 Pesapal (cards, bank and other wallets)
Create a merchant account, put consumer key/secret in `pesapal`. The IPN URL `https://www.waclouds.com/webhooks/pesapal` is registered automatically on first payment.

**Payment security model:** callbacks are never trusted on their own — the platform always re-queries the provider's status API and checks amount and currency before settling. Bank transfers stay *pending* until a Finance Officer ticks "Matched on bank statement" and verifies. Cron re-checks pending mobile payments every 5 minutes to cover missed callbacks.

### 6.5 Video meetings
Set `meetings.provider` (or *Admin → Settings → Bookings*) to one of:
- **zoom** — Zoom Marketplace → *Server-to-Server OAuth* app with scope `meeting:write:admin` (or `meeting:write:meeting:admin`); set account_id, client_id, client_secret, host_email.
- **google** — Google Cloud service account with Calendar API enabled and **domain-wide delegation** (scope `https://www.googleapis.com/auth/calendar.events`) in Google Workspace; upload the JSON key to `wacloud/storage/google-service-account.json`; set `impersonate` to the calendar owner.
- **teams** — Azure app registration with application permission `OnlineMeetings.ReadWrite.All`, admin consent, and an **application access policy** allowing the organizer user.
- **jitsi** — no setup; used as automatic fallback if the chosen provider fails.

Mark consultants: *Admin → Users & Roles → Edit → "Takes consultation bookings"*. Set hours under *Meetings & Bookings → Availability* and holidays under *Blocked dates*.

### 6.6 SMS & WhatsApp
- **SMS:** Africa's Talking account (works in Uganda); username, API key and approved sender ID.
- **WhatsApp:** Meta WhatsApp Cloud API — phone number ID and a permanent access token. Business-initiated WhatsApp messages must use **approved templates**: in *Admin → Communications → templates*, set a WhatsApp template's Subject to `tpl:<template_name>:<language>` (e.g. `tpl:payment_received:en`).

### 6.7 CAPTCHA
Default is a built-in arithmetic check + honeypot + timing check (no third party). For stronger protection set `captcha.provider` to `turnstile` (Cloudflare) or `recaptcha` with keys.

### 6.8 Analytics & Search Console
- *Admin → Settings → SEO & analytics*: GA4 Measurement ID and Search Console verification code.
- In Search Console submit `https://www.waclouds.com/sitemap.xml`.
- Optional client reporting: enable `google_analytics_api` and add the service account e-mail as a user on each client's GA4 property / Search Console property; then set the property IDs on the client's website record.

## 7. Cron
cPanel → Cron Jobs → every 5 minutes:
```
*/5 * * * * /usr/local/bin/php /home/CPANELUSER/wacloud/cron/run.php >/dev/null 2>&1
```
It sends meeting reminders, re-verifies pending payments, syncs domain registrations, and once a day: renewal invoices, overdue marking, reminders, suspension, housekeeping and a compressed database backup (14 kept). Check *Admin → System Health* to confirm it runs.

## 8. Backups & recovery
- Daily logical backups: `wacloud/storage/backups/*.sql.gz` (download from *System Health*).
- Also enable cPanel / JetBackup full-account backups and copy them off-server weekly.
- Restore: create an empty database, `gunzip -c backup.sql.gz | mysql -u USER -p DBNAME`, restore `wacloud/storage/uploads` and `public_html/uploads`.

## 9. Security checklist
- [ ] `app.env` = `production`, unique `app.key`
- [ ] HTTPS enforced (`public_html/.htaccess` already redirects to `https://www.`)
- [ ] `wacloud/` is outside `public_html`
- [ ] Strong Super Admin password; create individual staff accounts with the least role needed
- [ ] WHMCS API restricted to server IP
- [ ] SMTP SPF, DKIM and DMARC set for waclouds.com
- [ ] Off-site backups scheduled
- [ ] Replace placeholder bank details in `config.php → bank.instructions`

## 10. Nginx (VPS)
```
root /var/www/public_html;
location / { try_files $uri /index.php?$query_string; }
location ~ \.php$ { include fastcgi_params; fastcgi_pass unix:/run/php/php8.3-fpm.sock; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; }
location ~ /\.(?!well-known) { deny all; }
```
