# Moving to a new domain (with your existing SQL dump)

This guide is for exactly your situation: you have a SQL export from the old
domain and want the same app running on a new domain/hosting account.

## 0. What's in this zip

Everything needed to run the app: application code, `vendor/` (PHP
dependencies — no `composer install` required), and compiled front-end assets
in `public/build/` (no `npm run build` required). Just upload and configure.

**Not included** (must be handled separately — see step 6):
- Your database — that's your SQL dump, imported separately.
- Real uploaded files in `storage/app/public/` (site logos, customer
  payment-proof screenshots). These live on disk, not in the database, so a
  SQL dump alone does NOT bring them over.
- `.env` — you create this fresh from `.env.production.example` (step 4).

## 1. Upload

Extract the zip and upload everything to your new hosting account so that the
`public/` folder is what the domain's document root points to (in cPanel:
"Domains" → set the document root to `.../public`, or if you can't change the
document root, upload the app one level above `public_html` and move only the
*contents* of `public/` into `public_html`, adjusting the two `require`
paths at the top of `public_html/index.php` to point at the app folder).

## 2. Create the database

In cPanel → MySQL Databases, create a new database and a user with full
privileges on it. Note the database name, username, and password — you'll
need them in step 4.

## 3. Import your SQL dump

cPanel → phpMyAdmin → select the new database → Import → choose your `.sql`
file → Go. This restores all your real users, campaigns, subscriptions,
traffic logs, and settings exactly as they were on the old domain.

## 4. Configure `.env`

Copy `.env.production.example` to `.env` and fill in:

- `APP_URL` — the new domain, e.g. `https://newdomain.com`
- `DB_DATABASE`, `DB_USERNAME`, `DB_PASSWORD` — from step 2
- `MAIL_FROM_ADDRESS` — must be a domain hosted on this account
- `SETUP_TOKEN` — any long random string (used once in step 5, then removed)

Leave `APP_KEY` blank — the installer generates a fresh one for you. **Do not
reuse the old domain's key.**

## 5. Run the one-time installer

Visit:

```
https://newdomain.com/__setup/<YOUR_SETUP_TOKEN>
```

The installer automatically detects that your database already has data (from
the SQL dump) and:
- generates a fresh `APP_KEY`
- runs **only** any migrations newer than your dump (safe — it will not touch
  or duplicate your existing rows)
- does **NOT** re-seed demo/admin accounts (your real accounts are already
  there from the dump)
- links storage and caches config/routes/views

Read the on-screen output to confirm it says "Detected an EXISTING database"
before it runs. If it instead says "Detected an EMPTY database", stop —
that means your SQL import didn't take, and running it would seed demo data
instead of using your real data.

**Then immediately remove `SETUP_TOKEN` from `.env`** (or delete
`app/Http/Controllers/SetupController.php` and its route in `routes/web.php`).

## 6. Bring over uploaded files (not in the SQL dump)

From your **old** hosting account, copy these folders to the same paths on
the new one (FTP/SFTP, or cPanel File Manager download+upload):

- `storage/app/public/payment-proofs/` — customer payment-proof screenshots
  (subscription requests reference these by filename; without them, admins
  will see broken images for past submissions)
- `storage/app/public/` — any uploaded site logos / branding images
- `storage/app/geoip/*.mmdb` — **only** if you use the "Local GeoLite2"
  IP-intelligence provider (skip this if you use MaxMind web service or the
  free ip-api.com provider — those need no files, and your provider choice
  itself already carried over from the SQL dump since it's an admin setting).

These files can contain customer data — move them yourself directly between
your own accounts (FTP/SFTP or cPanel File Manager), rather than emailing or
uploading them anywhere else.

## 7. Verify

- Load `https://newdomain.com/` — homepage renders.
- Log into `/admin` with your existing admin account (same password as
  before — it came from the dump).
- Log into `/dashboard` as an existing client — same password as before.
- Open a campaign, confirm the tracking link now shows the **new** domain
  (it's generated from `APP_URL`, so this is automatic).
- Test one campaign's `/e/{hash}` endpoint or landing-page snippet to confirm
  traffic filtering still works end to end.

## Notes

- Campaign tracking links (`/c/{hash}`) and on-page endpoints (`/e/{hash}`)
  automatically use the new domain — nothing to update per campaign.
- All admin-configured settings (IP-intelligence provider/credentials,
  branding, plans, pricing) live in the database and come over with the SQL
  dump automatically.
- If you had a cron/scheduler configured for the old domain (queue worker,
  `schedule:run`), set that up again on the new host — cron jobs are
  server-level and are never part of an app zip or SQL dump.
