# Install AdNova Standalone Core

This package installs the PHP shared core with accounts, membership configuration, advertising-credit wallets, products and orders, and the traffic exchange. It does not install the full TE/Mailer product. Use a separate test domain and an empty, dedicated database for this milestone.

## 1. Select PHP and create a database

In DirectAdmin or cPanel, select PHP 8.3 or newer for the test domain and enable `pdo_mysql`, `mbstring`, `sodium` and `openssl`. Ensure the CLI command you use runs the same supported PHP branch; a server may have several versions installed.

Create an empty MySQL database and a database user through your hosting panel. Grant that user access to that database. Installation needs CREATE, ALTER, INDEX and normal SELECT/INSERT/UPDATE/DELETE permissions. Migration and installer locks use MySQL `GET_LOCK`; confirm your host permits it. Do not use the MySQL root account.

The code is verified on MySQL 8.0.46. Validate your host's MySQL/MariaDB version separately before treating this foundation as deployment-tested there.

## 2. Upload with a private application root

Extract the ZIP into an application folder, for example:

```
/home/USER/adnova
```

Configure the domain's document root as:

```
/home/USER/adnova/public
```

Only the `public/` directory is served by the web server. The configuration, application classes, migrations, tests and storage stay outside it. Do not upload the whole application into a publicly served `public_html` directory.

DirectAdmin/cPanel document-root controls vary by hosting configuration. For a primary domain whose document root cannot be changed from the user panel, ask the server administrator to set it; this package does not assume `.htaccess` can protect a misplaced application root.

For Apache/LiteSpeed, retain `public/.htaccess` and enable rewrite support. For Nginx, set `root` to the same `public/` directory and use a normal PHP-FPM configuration with `try_files $uri $uri/ /index.php?$query_string;`. Verify that only existing PHP files under the public root are passed to PHP-FPM. A specific PHP-FPM socket path depends on the host and is intentionally not guessed here.

## 3. Configure

From the application directory:

```sh
cp .env.example .env
php bin/console key:generate
```

Paste the generated key into `APP_KEY` in `.env`. Set:

- `APP_ENV="production"`
- `APP_NAME="Your site name"`
- `APP_URL="https://your-test-domain.example"` — origin only, with no subdirectory.
- `DB_HOST`, `DB_PORT`, `DB_NAME`, `DB_USER`, `DB_PASSWORD`.
- `DB_SOCKET=""` for TCP; supply a socket only if required by your host.
- `REGISTRATION_ENABLED="false"`.

Double-quoted values use JSON escaping: use `\"` for a literal quote and `\\` for a backslash. Dollar signs, equals signs and `#` are literal inside quoted strings. Do not put credentials into command-line arguments or commit `.env` to source control.

Keep `.env` readable only by the application account (usually mode 600). The application account needs write access to `storage/` and its child directories, including `storage/mail/`. Do not use world-writable permissions as a shortcut. PHP-FPM and CLI should run as the same site account or have deliberately configured shared permissions.

The bundled `vendor/` directory is ready to use. If rebuilding from source, run `composer install --no-dev --optimize-autoloader` before installation.

## 4. Create the owner

**Without SSH:** add `INSTALL_TOKEN="…"` (24+ random letters and numbers) to `.env`, open `https://your-domain/install`, confirm the server checks, and enter the token and owner details. Remove `INSTALL_TOKEN` from `.env` afterwards. The page is closed once AdNova is installed.

**With SSH:**

Run:

```sh
php bin/console install
```

Enter the owner name, email address and a 12–72-byte password when prompted. Password input is hidden. Use the actual site account, not a public registration form, to create the owner.

The command creates tables, then saves the owner, installation state and audit event together. If the account transaction fails it rolls back. MySQL DDL commits separately; the foundation CREATE migrations can resume after interruption.

Rerunning installation will not replace an existing owner. Removing `storage/installed.lock` does not reopen setup: the database installation record remains authoritative. There is no web installer route.

For controlled automation, `php bin/console install --owner-json-stdin` reads a JSON object with `name`, `email`, and `password` from standard input. Keep that input private and out of shell history/logs.

Then run:

```sh
php bin/console check
```

Open `https://your-test-domain.example/login` and sign in with the owner credentials. `/admin` shows real member records and account audit events. Use `/admin/members` to search accounts and manage permitted changes; `/account` contains your own profile and password controls.

## 5. HTTPS and reverse proxies

Configure your web server to redirect HTTP to HTTPS before PHP processes requests. The application also redirects insecure production requests and uses secure, HttpOnly, SameSite cookies. TLS must be reported to PHP using the server's HTTPS flag or port 443. If TLS terminates at a reverse proxy, configure that mapping in the web server only for trusted proxies. The application does not trust arbitrary forwarded headers.

Similarly, authentication rate limiting reads `REMOTE_ADDR`. Configure your web server's trusted-proxy IP handling if needed, or proxied visitors may share one limit.

## 6. Configure account emails and cron

Set these values in `.env` using an authenticated SMTP mailbox on your server/provider:

```ini
MAIL_DRIVER="smtp"
MAIL_FROM_ADDRESS="noreply@your-domain.example"
MAIL_FROM_NAME="Your Site Name"
SMTP_HOST="mail.your-domain.example"
SMTP_PORT="587"
SMTP_ENCRYPTION="tls"
SMTP_USERNAME="noreply@your-domain.example"
SMTP_PASSWORD="your-mailbox-password"
```

Use `SMTP_ENCRYPTION="ssl"` with port 465 if your provider requires implicit TLS. Certificates must be valid for the configured hostname. Do not disable certificate verification to fix a configuration error. Configure SPF/DKIM and the mailbox according to your provider, then verify actual inbox receipt before opening registration.

Add this command to cron **every minute**, using your host's actual PHP binary and path:

```sh
php /home/USER/adnova/bin/console cron:run
```

It processes up to 10 account emails, removes expired authentication data and session files, returns traffic credits from surf pages nobody answered, sends a batch of member mailings and closes mailings whose click window ended. It does not send member advertising emails, expire memberships or process payments. Overlapping workers skip while the database worker lock is held.

To process queued account mail manually:

```sh
php bin/console mail:work
php bin/console mail:status
```

Sign in as owner, visit `/verify-email`, and request a verification email. Run the worker and confirm that the message reaches your real mailbox and its link verifies your account. Test `/forgot-password` next. This build was tested with local capture and a local TLS SMTP fixture; your actual provider has not been tested for you.

Only after those checks, set `REGISTRATION_ENABLED="true"`. Registrations create unverified members and queue a verification email. An unverified member can see account/verification screens but cannot enter the workspace. Owners/admins retain administration access while configuring delivery.

## Local registration testing

For local development only:

```ini
APP_ENV="local"
APP_URL="http://127.0.0.1:8789"
REGISTRATION_ENABLED="true"
MAIL_DRIVER="capture"
```

Start the development server from the application directory:

```sh
php -S 127.0.0.1:8789 -t public tests/router.php
```

Open `/register`, create a member, run `php bin/console mail:work`, and read the verification URL from the private capture JSON under `storage/mail/`. Confirm the email while signed in, then check that the member can open `/dashboard` and is denied access to `/admin`. Capture files contain live links: keep them private and remove them when testing is complete. Local mode accepts loopback requests only. Do not run PHP's development server publicly.

## Validation and troubleshooting

- Run `php bin/console check` to verify the selected PHP runtime, database and installation.
- A 503 page deliberately hides database/configuration errors. Use its request reference to find the corresponding entry in the host's PHP error log.
- A 419 page means the CSRF token/session expired; reload the form.
- A 429 page means an authentication or account-control attempt limit was reached; wait 15 minutes.
- A 409 page means a form conflicts with newer settings or balances. Reload, review the current values and submit again.
- If sessions cannot be saved, fix the ownership/permissions of `storage/sessions/`.
- Keep `.env`, all passwords, database dumps and session files private. Never distribute them with a release ZIP.
- Use `/forgot-password` for recovery after configuring account email. Keep owner credentials securely during setup; do not clear installation state to regain access.
- Verification and reset URLs initially contain bearer tokens. Configure web-server access logs to omit/redact query strings for `/verify-email/link` and `/reset-password/link`. The app redirects to a clean URL, suppresses referrers and never logs token contents.

## Before later upgrades

Back up the database and `.env`, and verify the backup can be restored. Review new migration files before running `php bin/console migrate`. Applied migrations are checksum-protected and must not be edited. An automatic updater and in-app backup/restore workflow are still pending.

## Upgrade from version 0.9.0

From this version on you can update from the browser: **System & updates** → create and download a backup → turn on maintenance mode → upload the new files (keep `.env`, `storage/` and `addons/`) → **Apply database updates** → turn maintenance mode off.

For this upgrade: back up, replace the files, run `php bin/console migrate` (or use System & updates once the new files are in place), then `php bin/console wallet:check`. Migrations 039–040 add the import map and legacy-password tables; 001–038 are unchanged. You do not need to create `storage/backups/`: it is created on first use with private permissions.

## Upgrade from version 0.8.0

1. Back up the database, application files and `.env`, and verify restoration. Pause web requests and cron while replacing files and migrating.
2. Replace code and bundled `vendor/` with this release. Preserve `.env`, **APP_KEY** and existing storage.
3. Run `php bin/console migrate`, then `php bin/console check` and `php bin/console wallet:check`.
4. Migrations 033–038 add referral codes, referrals, link visits, payouts, commissions and credit-share progress. Migrations 001–032 are unchanged. Existing members have no referrer; referral links start working immediately.
5. Resume requests and cron. As owner, open **Referrals & payouts**, review the settings and payout methods, and check each level's **Referral commission** under Membership levels.

Keep `APP_KEY` unchanged: it signs referral cookies and encrypts payout details.

## Upgrade from version 0.7.0

1. Back up the database, application files and `.env`, and verify restoration. Pause web requests and cron while replacing files and migrating.
2. Replace code and bundled `vendor/` with this release. Preserve `.env`, **APP_KEY** and existing storage.
3. Run `php bin/console migrate`, then `php bin/console check` and `php bin/console wallet:check`.
4. Migrations 031–032 add payment attempts and provider events. Migrations 001–030 are unchanged.
5. Resume requests and cron. Online payments stay off until you add provider keys.
6. To turn them on, copy the `PAY_…` lines from `.env.example` into `.env`, fill in **test/sandbox** keys first, and follow [docs/PAYMENTS.md](docs/PAYMENTS.md) to register each webhook address shown on **Products**. Make a test purchase with each provider before switching to live keys.

Make sure the PHP `curl` extension is enabled and the server can make outgoing HTTPS requests. Configure access logs to omit query strings for `/pay/return/` addresses.

## Upgrade from version 0.6.0

1. Back up the database, application files and `.env`, and verify restoration. Pause web requests and cron while replacing files and migrating.
2. Replace code and bundled `vendor/` with this release. Preserve `.env`, **APP_KEY** and existing storage.
3. Run `php bin/console migrate`, then `php bin/console check` and `php bin/console wallet:check`.
4. Migrations 027–030 add mailings, recipients, mailing preferences and daily mail statistics. Migrations 001–026 are unchanged.
5. Resume requests and the one-minute cron (it now also sends member mailings).
6. As owner, open **Mailings** and review the mailer settings, especially the batch size (check your host's hourly email limit) and the footer. Check each level's daily mailings and recipients under **Membership levels**. Send a test mailing between two test members and read it from the email and from **Mail inbox**.

From 0.4.0 or 0.5.0, a single `migrate` applies every newer migration in order; still read the steps for each version below.

Keep `APP_KEY` unchanged: it signs the unsubscribe links in emails already sent. Configure web-server access logs to omit query strings for `/mail/click` as you did for account links.

## Upgrade from version 0.5.0

1. Back up the database, application files and `.env`, and verify restoration. Pause web requests and cron while replacing files and migrating.
2. Replace code and bundled `vendor/` with this release. Preserve `.env`, **APP_KEY** and existing storage.
3. Run `php bin/console migrate`, then `php bin/console check` and `php bin/console wallet:check`.
4. Migrations 020–026 add wallet activity totals, sites, surf pages, surfer state, daily surf and site statistics, and site reports. Migrations 001–019 are unchanged; existing data is untouched.
5. Resume requests and the one-minute cron (it now also returns credits from unanswered surf pages).
6. As owner, open **Traffic settings** and review the defaults. Check each membership level's surf timer and ratio under **Membership levels**. Then add a test site as one member, approve it in **Site review**, assign credits, and surf it from a second member.

Upgrading from 0.4.0: follow the 0.4.0 steps below first, or run `migrate` once — it applies 015–026 in order.

The surf page must be served over HTTPS in production, and only `https://` member sites can be shown in its frame. See [docs/TRAFFIC-EXCHANGE.md](docs/TRAFFIC-EXCHANGE.md).

## Upgrade from version 0.4.0

1. Back up the database, application files and `.env`, and verify restoration. Pause web requests and cron while replacing files and migrating.
2. Replace code and bundled `vendor/` with this release. Preserve `.env`, **APP_KEY** and existing storage.
3. Run `php bin/console migrate`, then `php bin/console check` and `php bin/console wallet:check`.
4. Migrations 015–019 verify the existing owner's email and add settings, products, orders and payments. Migrations 001–014 are unchanged. Existing accounts, memberships and balances are untouched.
5. Resume requests and cron. As owner, open **Products**, write your manual payment instructions, then create a test product (hidden or with a test member). Order it as a verified test member, then fulfil it from **Orders** and confirm the credits and membership.

No new cron job is needed. See [docs/COMMERCE.md](docs/COMMERCE.md) for order, renewal and payment rules.

## Upgrade from version 0.3.0

1. Back up the database, application files and `.env`, and verify restoration. Pause web requests and cron while replacing files and migrating.
2. Replace code and bundled `vendor/` with this release. Preserve `.env`, **APP_KEY** and existing storage.
3. Run `php bin/console migrate`, then `php bin/console check` and `php bin/console wallet:check`.
4. Migrations 008–014 add plans, the default Free level, membership assignments, credit balances, transaction entries and core audit/idempotency records. Migrations 001–007 are unchanged. Existing accounts remain intact; everyone without an assignment inherits Free and starts with zero credit balances. No legacy or prototype balances are imported.
5. Resume requests and cron. As owner, open Membership levels to configure plans. Open Members, select a test account, then Manage membership and credits. Verify a membership assignment and credit adjustment on that test member.

No additional cron is required for membership expiry: effective membership is evaluated on each read. The account-mail cron continues unchanged. Owner access is required to configure levels, assign memberships and issue/deduct credits. Administrators retain existing account controls but cannot make these core changes.

See [docs/MEMBERSHIPS-WALLET.md](docs/MEMBERSHIPS-WALLET.md) for duration, snapshot and credit rules. Assignment replaces remaining time; it is not an automatic renewal, subscription or payment.

## Upgrade from version 0.2.0

1. Back up the database, application files and `.env`, and verify that the backup can be restored. Pause web requests and the account-mail cron while replacing files and migrating.
2. Replace code and bundled `vendor/` with this release. Preserve `.env`, its **APP_KEY**, and existing storage.
3. Run `php bin/console migrate`, then `php bin/console check`. Migrations 007–014 add member audit details and the shared core; migrations 001–006 are unchanged. Existing users, passwords and roles are retained.
4. Resume requests and cron. Sign in as owner, open `/admin/members`, and verify account search. Test a display-name edit and its history on a dedicated test member before making access changes.

This is a manual code/database upgrade. An automatic updater is not included. See [docs/MEMBER-MANAGEMENT.md](docs/MEMBER-MANAGEMENT.md) for permissions and session behavior.

## Upgrade from version 0.1.0

1. Back up your database, application files and `.env`.
2. Replace code and bundled `vendor/` with this release. Preserve `.env` and all existing storage. Create `storage/mail/` with the same private ownership as the session directory.
3. Add the new MAIL/SMTP settings from `.env.example`. Keep your existing **APP_KEY unchanged**; it now encrypts queued account-email payloads as well as protecting rate-limit identities.
4. Run `php bin/console migrate`. New migrations 005–014 add account tokens, email queue, audit details and the shared core. Migrations 001–004 are unchanged. Existing users/passwords are retained; they are not automatically marked verified.
5. Test owner verification and recovery, add the one-minute cron, then enable registration if desired.

Verification links last 24 hours; reset links last 30 minutes. Requesting a replacement invalidates the old link of that type. A password reset changes the password, revokes existing sessions and removes all outstanding account links; it does not automatically mark the email verified.

Delivery retries happen after five minutes, up to three attempts. A worker interrupted mid-delivery may retry a stale claim after ten minutes. SMTP acceptance is not proof of inbox delivery, and a crash after acceptance can send the same email twice. The link remains single use. Failed messages are visible as counts in administration; request a new link after fixing SMTP to create a fresh attempt. Obsolete/expired queued payloads are removed by cron.
