# Namecheap/cPanel Deployment Guide

This app is a Next.js Node.js application. phpMyAdmin/MySQL is supported for the database, but the web app must run through cPanel **Setup Node.js App** rather than Apache-only static hosting.

## Database Setup

1. Log in to cPanel.
2. Open MySQL Database Wizard or Manage My Databases.
3. Create a database.
4. Create a database user.
5. Assign the user to the database.
6. Grant the needed privileges.
7. Record cPanel-prefixed database and username values.
8. Build `DATABASE_URL` with URL-encoded password characters.
9. Verify the database in phpMyAdmin.

Example:

```env
DATABASE_URL="mysql://cpaneluser_pmapuser:encoded_password@localhost:3306/cpaneluser_pmapconference?connection_limit=5"
```

Use `prisma migrate deploy` for production schema updates. Do not use `prisma migrate dev` on cPanel.

## Node.js App Manager

1. Open Setup Node.js App.
2. Create a Node.js application.
3. Select Node.js 20 LTS or newer.
4. Set mode to production.
5. Set application root to the uploaded `pmap-annual-conference` folder.
6. Set application URL.
7. Set startup file to `server.js`.
8. Configure environment variables.
9. Run dependency install.
10. Run `pnpm cpanel:migrate`.
11. Run `pnpm cpanel:build`.
12. Restart the application.

If cPanel does not expose `pnpm`, install dependencies from SSH or cPanel Terminal using the package manager available on the host, then run the same scripts from the uploaded app folder.

## Required Environment Variables

Set these in cPanel Setup Node.js App:

```env
APP_ENV="production"
APP_URL="https://your-domain.example"
DATABASE_URL="mysql://cpaneluser_pmapuser:encoded_password@localhost:3306/cpaneluser_pmapconference?connection_limit=5"
SESSION_SECRET="replace-with-32-plus-random-characters"
CRON_SECRET="replace-with-a-long-random-cron-secret"
UPLOAD_ROOT="./uploads"
```

Set these when production email sending should work:

```env
SMTP_HOST="mail.your-domain.example"
SMTP_PORT="587"
SMTP_SECURE="false"
SMTP_USERNAME="no-reply@your-domain.example"
SMTP_PASSWORD="your-email-password"
SMTP_FROM_EMAIL="no-reply@your-domain.example"
SMTP_FROM_NAME="PMAP Annual Conference"
```

## Build and Start Commands

From the uploaded application root:

```bash
pnpm cpanel:install
pnpm env:verify
pnpm cpanel:migrate
pnpm cpanel:build
pnpm cpanel:start
```

In cPanel, the app startup file should be:

```text
server.js
```

The startup file loads the standalone Next.js server generated at `apps/web/.next/standalone/apps/web/server.js`. The `cpanel:build` script also copies `.next/static` and `public` assets into the standalone folder.

## Production Smoke Tests

After restarting the Node.js app, verify:

1. `https://your-domain.example/api/v1/health`
2. `https://your-domain.example/admin/login`
3. Admin login over HTTPS
4. Participant login over HTTPS
5. Participants list and QR generation
6. Password reset email logging or SMTP sending
7. Tables are visible in phpMyAdmin

## Cron Jobs

Run every five minutes:

```bash
cd /home/CPANEL_USER/pmap-annual-conference && pnpm jobs:process
```

Or call the protected endpoint:

```bash
curl -X POST -H "x-cron-secret: $CRON_SECRET" https://your-domain.example/api/v1/cron/process-jobs
```

## SSL

Use AutoSSL, redirect HTTP to HTTPS, and set `APP_URL` to the HTTPS URL. Secure cookies should only be enabled when HTTPS is active.

## File Permissions

Keep `.env` non-public, restrict export folders, and ensure `uploads/` cannot execute scripts. Block `.php`, `.phtml`, `.phar`, `.cgi`, `.pl`, `.sh`, `.exe`, `.js`, and `.html` uploads.
