# NEXTUK Consultant — live install (nextukconsultant.com)

Deploy this package on a PHP/MySQL host with the domain **https://nextukconsultant.com**.

## Requirements

- PHP **8.1+** (8.2/8.3 recommended) with extensions: `pdo_mysql`, `mbstring`, `curl`, `openssl`, `json`, `fileinfo`
- MySQL **5.7+** or MariaDB **10.3+**
- Apache with `mod_rewrite` (or equivalent nginx rules)
- HTTPS certificate for `nextukconsultant.com` (and `www` if used)

## 1. Upload

1. Upload and unzip `nextukconsultant-live.zip` on the server (outside or inside your hosting account).
2. Point the domain **document root** at the **`public`** folder inside the project.  
   Example path: `/home/you/nextukconsultant/public`
3. Ensure these folders are writable by the web server:
   - `storage/uploads`
   - `storage/mail`
   - `storage/backups`

```bash
chmod -R 775 storage
```

## 2. Configure

```bash
cp config/config.example.php config/config.php
```

Edit `config/config.php`:

| Setting | Live value |
|--------|------------|
| `env` | `production` |
| `base_path` | `''` (empty) when the site is at the domain root |
| `url` | `https://nextukconsultant.com` |
| `app_key` | New 64-char hex key (see below) |
| `db.*` | Your hosting MySQL host, database, user, password |
| `demo.*` | Emails/passwords for the first staff and demo client |

Generate a new encryption key:

```bash
php -r "echo bin2hex(random_bytes(32)), PHP_EOL;"
```

Paste that into `app_key`.

Copy the production rewrite rules (required when the site is at domain root):

```bash
cp public/.htaccess.production public/.htaccess
```

## 3. Create the database

Create an empty MySQL database and user in your host control panel, matching `config/config.php`.

From SSH (in the project root):

```bash
php database/install.php
```

If the database already exists and you want a clean rebuild:

```bash
php database/install.php --force
```

The installer prints:

- Site URL  
- Admin portal URL (`/adminportalerp` by default)  
- Admin / support / finance / demo client logins  
- Cron key  

**Change all demo passwords after first login.**

## 4. DNS / SSL

1. Point `nextukconsultant.com` (and `www` if needed) to the server.
2. Enable HTTPS in the host panel (Let’s Encrypt or your certificate).
3. Prefer forcing HTTPS so cookies and payment returns stay secure.

## 5. Cron (renewals & filing reminders)

Run once daily (adjust the path):

```bash
0 7 * * * /usr/bin/php /home/you/nextukconsultant/cron/reminders.php >/dev/null 2>&1
```

Or call the HTTP cron endpoint with the key printed by the installer (see admin settings → cron key).

## 6. First login checklist

1. Open **https://nextukconsultant.com/**
2. Staff: **https://nextukconsultant.com/adminportalerp**
3. Admin → **Settings**: company name, support emails, VAT, Stripe/PayPal/GoCardless keys if taking live payments
4. Admin → **Offices / Services / Coupons** as needed
5. Switch payment mode to live only after real gateway keys are saved
6. Delete or suspend the demo client if you do not want it on production

## 7. nginx (if not Apache)

Document root → `.../public`. Example:

```nginx
server {
    listen 443 ssl http2;
    server_name nextukconsultant.com www.nextukconsultant.com;
    root /home/you/nextukconsultant/public;
    index index.php;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ \.php$ {
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_pass unix:/run/php/php8.2-fpm.sock;
    }

    location ~* /\.(?!well-known).* {
        deny all;
    }
}
```

Do **not** expose `app/`, `config/`, `database/`, or `storage/` as public URLs.

## Troubleshooting

| Problem | Check |
|--------|--------|
| 404 on all pages | Document root is `public`; `.htaccess` RewriteBase is `/` |
| Database is not ready | `config/config.php` DB credentials; run `php database/install.php` |
| Blank / 500 page | Set `env` to `local` temporarily to see the error, then set back to `production` |
| Uploads / KYC fail | `storage` permissions (`775`) and disk space |
| Admin URL 404 | Use `/adminportalerp` (or whatever you set in `admin_portal`) |

## Package contents

```
app/                 Application code
config/              config.example.php → copy to config.php
cron/                Reminder CLI
database/            schema.sql + install.php
public/              Web root (index.php, assets, .htaccess)
storage/             uploads, mail, backups (writable)
INSTALL.md           This file
```
