# Where to copy this, and what not to break

## The short answer

**Do NOT copy this package into `public_html/aiseo/`.** That folder already
contains your working app, which owns `index.php`. Two apps cannot share one
front controller, and overwriting it is what takes the site down.

**Copy the whole package, as-is, into a NEW folder instead:**

```
public_html/aiseo-new/
```

Nothing gets rearranged. Every folder lands exactly as it is in the zip. Your
existing `/aiseo/` keeps running while you set the new one up, and you can test
both side by side and switch over only when the new one works.

---

## Option A — new folder (recommended)

### 1. Upload

Extract the zip and upload the **whole tree** to `public_html/aiseo-new/`. When
you are done it looks like this — identical to the zip:

```
public_html/aiseo-new/
├── .htaccess              <- from deploy/htaccess-A-separate-folder.txt
├── .env                   <- you create this from .env.example
├── bootstrap.php
├── preflight.php
├── public/
│   ├── index.php
│   ├── styleguide.html
│   └── assets/css/, assets/js/
├── config/
├── src/
├── templates/
├── db/migrations/
├── bin/
├── tests/
├── render-service/
└── var/
```

### 2. The one file you must place by hand

Copy `deploy/htaccess-A-separate-folder.txt` to `public_html/aiseo-new/.htaccess`
and edit one line inside it to match the folder name:

```
RewriteBase /aiseo-new/
```

### 3. Create .env

```bash
cd ~/public_html/aiseo-new
cp .env.example .env
chmod 600 .env
```

Then set at minimum:

```
APP_URL=https://dghanalytics.com/aiseo-new
APP_KEY=<run: php -r "echo bin2hex(random_bytes(32));">
DB_NAME=dolrad_...
DB_USER=dolrad_...
DB_PASS="your password in double quotes"
```

Leave every `AISEO_*_DIR` line blank. In this layout the defaults are correct and
auto-discovery finds everything.

### 4. Permissions

```bash
chmod 755 var var/logs var/cache
chmod 600 .env
```

### 5. Check before doing anything else

```
https://dghanalytics.com/aiseo-new/preflight.php
```

Then, once it is clean:

```bash
php bin/doctor.php
php bin/migrate.php
php bin/audit.php --list
```

### 6. Delete preflight.php

It exposes paths and PHP configuration. Remove it once the app runs.

### 7. Switching over, later

When the new app works and you want it at `/aiseo/`:

```bash
cd ~/public_html
mv aiseo aiseo-old-$(date +%Y%m%d)      # keep the old one, do not delete it
mv aiseo-new aiseo
# then in aiseo/.env:  APP_URL=https://dghanalytics.com/aiseo
# and in aiseo/.htaccess:  RewriteBase /aiseo/
```

Two lines to edit, and the old app is still on disk if you need it back.

---

## Option B — into the existing `/aiseo/` folder

Only if you have decided to replace your current app now. **Back it up first:**

```bash
cd ~/public_html
cp -a aiseo aiseo-backup-$(date +%Y%m%d)
```

Then the package folders map like this. Note that the **contents** of `public/`
move up one level, because your front controller is served at `/aiseo/` directly:

| From the zip | To |
|---|---|
| `bootstrap.php` | `aiseo/bootstrap.php` |
| `preflight.php` | `aiseo/preflight.php` |
| **contents of** `public/` | `aiseo/` — so `aiseo/index.php`, `aiseo/assets/`, `aiseo/styleguide.html` |
| `config/` | `aiseo/config/` |
| `src/` | `aiseo/3-source-code/src/` (merges with what you already have) |
| `templates/` | `aiseo/3-source-code/templates/` |
| `db/migrations/` | `aiseo/3-source-code/db/migrations/` |
| `bin/` | `aiseo/bin/` |
| `tests/` | `aiseo/tests/` |
| `render-service/` | `aiseo/render-service/` |
| `var/` | `aiseo/var/` |
| `deploy/htaccess-B-front-controller-at-root.txt` | `aiseo/.htaccess` |

Do **not** create `aiseo/public/` — the app would end up served at
`/aiseo/public/`.

Then set the explicit paths in `.env`, because in this layout the source is not
where the package defaults expect:

```
AISEO_SRC_DIR=/home/dolrad/public_html/aiseo/3-source-code/src
AISEO_TEMPLATES_DIR=/home/dolrad/public_html/aiseo/3-source-code/templates
AISEO_MIGRATIONS_DIR=/home/dolrad/public_html/aiseo/3-source-code/db/migrations
AISEO_PUBLIC_DIR=/home/dolrad/public_html/aiseo
AISEO_VAR_DIR=/home/dolrad/aiseo-var
APP_URL=https://dghanalytics.com/aiseo
```

Replace `/home/dolrad/public_html` with your real account path — run `pwd` in the
cPanel terminal to confirm it.

---

## Getting your current site back right now

`/aiseo/` is returning 500 and static files still serve, which means PHP is
failing, not Apache. To restore what you had:

1. Put your original `index.php` back from your backup or from git.
2. If you also replaced `.htaccess`, rename mine: `mv .htaccess .htaccess.mine`
3. Reload. Your old app should return.

Nothing of mine touches `3-source-code/src` in a destructive way — the package
adds files there, it does not delete yours. The only file of mine that replaces
one of yours is `index.php`, plus `.htaccess` if you copied it.

If you do not have a backup of `index.php`, say so — the app's own source is
still on disk in `3-source-code/`, so it is recoverable.

---

## Upload notes that cause blank 500s

- **Use binary mode**, or upload the zip and extract it with cPanel File Manager.
  FTP in text mode mangles line endings and can truncate a `.php` file, which
  produces a parse error and an empty 500.
- **Extract server-side if you can.** Upload `aiseo-code.zip`, then File Manager
  → right-click → Extract. Far fewer failure modes than transferring 51 files.
- **Check file permissions after extracting:** files 644, folders 755,
  `.env` 600, `var/` and its subfolders 755.
- **Filenames are case-sensitive on Linux.** `SearchConsole.php` must not become
  `searchconsole.php`. Extracting the zip preserves case; a Windows drag-and-drop
  over FTP sometimes does not.
