# cPanel Deployment Guide

This project is a Next.js Node application, so the cPanel account must support Node.js apps. The installed Prisma packages require Node.js 20.19.0 or newer within Node 20, Node.js 22.12.0 or newer within Node 22, or Node.js 24.0.0 or newer.

## 1. Create The Database

In cPanel, create a MySQL or MariaDB database and user, then assign the user to the database with all required privileges.

Example cPanel names:

```text
Database: cpanel_user_mytree
User:     cpanel_user
Host:     localhost
Port:     3306
```

## 2. Configure Environment Variables

Copy `.env.example` to `.env` on the server and replace the placeholders:

```text
DATABASE_URL="mysql://cpanel_user:strong_password@localhost:3306/cpanel_user_mytree"
NODE_ENV="production"
```

If your password contains special URL characters, URL-encode it or use the split `DB_HOST`, `DB_PORT`, `DB_NAME`, `DB_USER`, and `DB_PASSWORD` values from `.env.example`.

For OTP email delivery, add these SMTP values in cPanel's Node.js environment variables or in the server `.env` file:

```text
SMTP_ENABLED="true"
SMTP_HOST="mytree.zeeface.com"
SMTP_PORT="465"
SMTP_SECURE="true"
SMTP_USER="admin@mytree.zeeface.com"
SMTP_PASSWORD="your-smtp-password"
SMTP_FROM_NAME="MyTree"
SMTP_FROM_EMAIL="admin@mytree.zeeface.com"
SMTP_REPLY_TO="admin@mytree.zeeface.com"
```

The webmail/cPanel URL on port `2080` is not used for SMTP. The app sends OTP email through the outgoing SMTP server `mytree.zeeface.com` on port `465`.

## 3. Create Tables

Use one of these options.

Option A, terminal migration:

```bash
npm install
npm run db:migrate
```

Option B, phpMyAdmin import into an empty database:

```text
database/mytree.sql
```

The Prisma migration and SQL import create the same application tables: users, KYC documents, trees, monitoring reports, donations, and wallet transactions.

## 4. Build And Start

Before installing dependencies, confirm cPanel is using a supported Node.js version:

```bash
node -v
npm -v
```

Use Node.js `20.19.0+`, `22.12.0+`, or `24.0.0+`. If cPanel only offers older Node 20 builds such as `20.18.x`, select Node 22 or ask the host to enable a newer runtime.

Run install commands from the project root, where `package.json`, `prisma.config.ts`, and the `prisma/schema.prisma` file are all present:

```bash
pwd
ls package.json prisma/schema.prisma prisma.config.ts
npm install
```

If `ls prisma/schema.prisma` fails, the deployment upload is incomplete or the terminal is in the wrong folder. Upload the `prisma` directory alongside `src`, `public`, `package.json`, and `server.js` before running `npm install`.

If you deploy using a ZIP file, make sure the ZIP extracts these files directly into the app root. Avoid archives that create an extra nested folder such as `mytree/package.json` and `mytree/prisma/schema.prisma`; in that case either set the cPanel application root to the nested `mytree` folder or re-upload a flat archive.

```bash
npm run build
npm run start
```

In cPanel's Node.js App screen, set the application root to this project folder, set the application startup file to `server.js`, and set the public URL to your domain or subdomain. If your cPanel screen supports a startup command instead of a startup file, use:

```bash
npm run start
```

The startup file defaults to production mode, but keep `NODE_ENV="production"` in the cPanel environment variables so Next.js and supporting tools all see the intended runtime.

## Useful Commands

```bash
npm run db:validate   # Validate prisma/schema.prisma
npm run db:generate   # Generate the Prisma client
npm run db:migrate    # Apply migrations to the configured database
npm run db:push       # Push schema directly when migrations are not needed
```
