# Installing The Meat Brand

You need a VPS with root access. Either kind works:

* **cPanel/WHM VPS** (e.g. CloudLoop). Your existing sites and email keep working.
* **Plain Ubuntu/Debian/AlmaLinux VPS.**

At least **4 GB RAM** (8 GB is more comfortable) and **20 GB free disk**.

## cPanel/WHM VPS: before you start

1. In **WHM → Create a New Account**, make sure there's a cPanel account for your platform
   domain (e.g. `meatbrand.com.au`). If you already have one, skip this.
2. Whatever is in that account's website folder will be replaced by the platform on
   `meatbrand.com.au` and `www.` (email is not affected). Back it up if you need it.

## Install (about 15 minutes)

1. Upload the zip anywhere on the server (cPanel File Manager is fine).
2. Open a root terminal: WHM → **Terminal**, or your host's **Console** button, or `ssh root@your-server`.
3. Move it out of the website folder and unpack it. Replace the path with where you uploaded it:
   ```bash
   mkdir -p /opt && cd /opt
   unzip /home/YOURUSER/public_html/meat-brand.zip -d /opt
   rm /home/YOURUSER/public_html/meat-brand.zip
   cd /opt/meat-brand
   ```
4. Run the installer:
   ```bash
   sudo bash install.sh
   ```
5. Answer the questions: your domain, your email, and an admin password.

When it finishes it prints your admin address: **https://app.YOURDOMAIN/admin**.
Sign in and set up two-factor with an authenticator app on your phone.

## DNS

These names must point at your server's IP. The installer prints the IP.

| Name | cPanel VPS | Plain VPS |
|---|---|---|
| `yourdomain`, `www`, `app`, `sites` | automatic if your DNS is in WHM | add A records |
| each client preview (`smiths.yourdomain`) | automatic | covered by a `*` (wildcard) A record |

Not sure where your DNS is managed? Ask your host: "Is DNS for meatbrand.com.au hosted on my VPS?"

## Adding client sites

**Admin → Add a client site.** Enter the business name, a site address and the owner's email.
You get an invite link to send the owner; they set their own password.
The preview site (`theiraddress.yourdomain`) and its SSL certificate appear within a few minutes.

When a client connects their own domain, they follow the DNS steps shown in their
dashboard. Once it's verified and their site is published, it's switched on automatically.

## Updating

Replace the files in `/opt/meat-brand` with the new version (your `.env` settings file is
kept: it isn't in the zip), then run:
```bash
cd /opt/meat-brand && sudo bash install.sh
```
It backs up the database, rebuilds, applies database changes and restarts.

## If something goes wrong

* Show the last messages: `cd /opt/meat-brand && docker compose logs --tail 60 api web`
* cPanel site sync log: `tail -50 /var/log/meatbrand-cpanel-sync.log`
* Put your old website back (cPanel): `bash scripts/cpanel-sync.sh --remove`
