# Putting the NAC website on cPanel

Written for a cPanel account with **Setup Node.js App**, for example `www.nac.edu.et`.
Allow about an hour the first time. Menu names can differ slightly between hosting companies.

What you need:
- **Setup Node.js App** in cPanel, with Node.js **22** (20.9 or newer works)
- **MySQL® Databases** in cPanel
- **SSL** for the domain (AutoSSL is fine). The admin panel only works over `https://`.
- **Terminal** in cPanel (or SSH) to run the one-time setup commands

---

## 1 — Make the upload package (on your computer)

In the project folder:

```bash
npm install
npm run build
npm run package
```

This creates `deploy/nac-website.zip`. It contains the website only — no passwords,
no database, no uploaded files.

---

## 2 — Create the database

**cPanel → MySQL® Databases**

1. *Create New Database*: type `nacweb` → **Create Database**
2. *Add New User*: type `nacweb`, use the password generator and **copy the password** — it is shown once
3. *Add User To Database*: pick the user and the database → **ALL PRIVILEGES** → **Make Changes**

cPanel adds your account name in front, so write down the real names, e.g. `nacedu_nacweb`.

---

## 3 — Create two folders

In **File Manager**, in your home folder (next to `public_html`, **not inside it**), create:

| Folder | Holds |
|---|---|
| `nac-website` | the program |
| `nac-storage` | uploaded photos and applicants' documents — keep it when you update the site |

---

## 4 — Upload the program

Open `nac-website`, upload `nac-website.zip`, right-click → **Extract** (extract into
`/home/<account>/nac-website`), then delete the zip. `server.js` should now sit directly inside
`nac-website`.

Tick **Settings → Show Hidden Files**: you should see a `.next` folder next to `server.js`.

---

## 5 — Create the settings file

In `nac-website`, create a file named `.env` with this content (use your own values):

```
DB_HOST=localhost
DB_PORT=3306
DB_USER=nacedu_nacweb
DB_PASSWORD=the-password-you-copied
DB_NAME=nacedu_nacweb
DB_POOL_SIZE=3

STORAGE_DIR=/home/<account>/nac-storage
SITE_URL=https://www.nac.edu.et
```

Right-click the file → **Change Permissions** → `600` (only you can read it).

Staff sign in at `https://www.nac.edu.et/login/admin`. The **Portal** button in the header opens `/login`, which only shows the old sign-in card and is not connected to anything.

---

## 6 — Create the Node.js application

**cPanel → Setup Node.js App → Create Application**

| Field | Value |
|---|---|
| Node.js version | 22.x |
| Application mode | Production |
| Application root | `nac-website` |
| Application URL | your domain, e.g. `www.nac.edu.et` |
| Application startup file | `server.js` |

Click **Create**. Then, on the same page, click **Run NPM Install** and wait until it finishes.

---

## 7 — Set up the database (one time)

Choose **one** of these two ways.

### 7a — Move the content you prepared on your computer (recommended if you tested locally)

Your programs, prices, news, photos and admin accounts are in your local database and in
the local `storage` folder. Copy both to cPanel:

1. On your computer, open **XAMPP → phpMyAdmin** (http://localhost/phpmyadmin), click the
   `nac_website` database → **Export** → *Quick*, format **SQL** → **Export**. A `.sql` file downloads.
2. On cPanel, open **phpMyAdmin**, click your new database (e.g. `nacedu_nacweb`) → **Import** →
   choose the `.sql` file → **Import**.
3. On your computer, zip the contents of `NAC website v2\storage` (the `media` and `applications` folders).
   In cPanel **File Manager**, upload the zip into `nac-storage` and **Extract** it, so that
   `nac-storage/media` exists.
4. Click **Restart** on the Node.js application page and continue with step 8.
   You sign in with the same admin accounts you used on your computer.

Before exporting, delete test applications and test messages in the admin panel so they do not go live.

### 7b — Start with an empty site on the server

On the Node.js application page, copy the command shown under
*"Enter to the virtual environment"*. Open **cPanel → Terminal**, paste it and press Enter.
You are now in the `nac-website` folder. Run:

```bash
npm run migrate
npm run seed
npm run seed:media
npm run prices
npm run brochure
npm run create-admin -- --username yourname --name "Your Full Name"
```

`create-admin` prints a **temporary password once** — write it down.

Back on the Node.js application page, click **Restart**.

---

## 8 — Check that it works

1. Open `https://www.nac.edu.et` — the homepage with programs should appear.
2. Open `https://www.nac.edu.et/login/admin` — sign in with the temporary password and choose your own.
3. In **Settings**, check the phone numbers, email and address.
4. In **Users & roles**, create an account for the registrar (role *Registrar*).
5. Send a test application from `/apply`, find it under **Applications**, then delete it.

---

## Updating the website later

1. On your computer: `npm run build` and `npm run package`.
2. In **Setup Node.js App**, click **Stop App**.
3. In File Manager, delete everything in `nac-website` **except `.env`**, upload the new zip and extract it as in step 4.
4. Click **Run NPM Install**.
5. In Terminal (step 7): `npm run migrate` — it only applies database changes that are new.
6. Click **Start App** (or **Restart**).

Uploaded photos and documents are safe because they live in `nac-storage`.

---

## Backups

Once a week, at least:
- **cPanel → phpMyAdmin** → select the database → **Export** → download the file.
- **File Manager** → right-click `nac-storage` → **Compress** → download the zip.

Keep the `.env` file somewhere safe as well.

---

## Troubleshooting

| What you see | What to check |
|---|---|
| "Application error" or 503 | Node.js version is 20.9+; **Run NPM Install** finished; the `stderr.log` file in `nac-website` |
| "Cannot find module" in Terminal | Run **Run NPM Install**, and enter the virtual environment first (step 7) |
| Pages show a database error | `DB_USER`, `DB_PASSWORD` and `DB_NAME` in `.env` match cPanel exactly (with the account prefix) |
| Signing in does nothing | The site must be opened with `https://` |
| Photos or documents fail to upload | `STORAGE_DIR` points to an existing folder that is not inside `public_html` |
| Forgot the admin password | In Terminal (step 7): `npm run create-admin -- --username yourname --reset` |
