# cPanel Deployment Guide (No Docker)

This guide covers deploying the **SEO · AEO · GEO Implementation Manager** on a **cPanel-based server** using **MySQL** and cPanel's **Setup Node.js App** (Phusion Passenger).

> **Note on Redis / BullMQ:** Shared cPanel hosting typically does not include Redis. All core features—adding sites, scanning & AI auditing pages (`mode: "sync"`), managing tasks, and **Verify Live**—work directly via HTTP requests **without Redis or the background worker**.

---

## 1. Prerequisites on cPanel

Ensure your cPanel account has:
* **Setup Node.js App** (Node.js **20.x** or **22.x** recommended)
* **MySQL Databases** (MySQL 8.0+ or MariaDB 10.6+)
* **SSH / Terminal** access (or cPanel File Manager + Git™ Version Control)

---

## 2. Create the MySQL Database

1. Open **cPanel → MySQL® Databases**.
2. Create a new database (e.g., `cpuser_seomgmt`).
3. Create a new MySQL user and strong password (e.g., `cpuser_seouser`).
4. Under **Add User to Database**, grant **ALL PRIVILEGES** to `cpuser_seouser` on `cpuser_seomgmt`.
5. Note your connection string:
   ```text
   mysql://cpuser_seouser:YOUR_PASSWORD@localhost:3306/cpuser_seomgmt
   ```
   *(If your password has special characters like `@`, `#`, `/`, `%`, URL-encode them.)*

---

## 3. Pull the Repository onto cPanel

### Option A: Using SSH / cPanel Terminal (Recommended)
```bash
cd ~
git clone https://github.com/krishna711/site-management.git seo-management
cd ~/seo-management
```

### Option B: Using cPanel Git™ Version Control
1. Go to **cPanel → Git™ Version Control → Create**.
2. Clone URL: `https://github.com/krishna711/site-management.git`
3. Repository Path: `/home/YOUR_CPANEL_USER/seo-management`

---

## 4. Configure Environment Variables

Create `.env` inside `~/seo-management`:
```bash
cp .env.example .env
nano .env
```

Set your production values:
```env
NODE_ENV="production"
DATABASE_URL="mysql://cpuser_seouser:YOUR_PASSWORD@localhost:3306/cpuser_seomgmt"

# AI Provider ("gemini" or "openai")
AI_PROVIDER="gemini"
GEMINI_API_KEY="your-gemini-api-key"
GEMINI_MODEL="gemini-2.5-flash"

# Optional: OpenAI
# OPENAI_API_KEY=""
# OPENAI_MODEL="gpt-4o-mini"

# Optional: Google Search Console & PageSpeed
# GOOGLE_SERVICE_ACCOUNT_JSON="/home/YOUR_CPANEL_USER/seo-management/gsc-key.json"
# PAGESPEED_API_KEY=""
```

---

## 5. Set Up the Node.js Application in cPanel

1. Go to **cPanel → Setup Node.js App → Create Application**.
2. Configure the fields:
   * **Node.js version:** `20.x` or `22.x` (latest available)
   * **Application mode:** `Production`
   * **Application root:** `seo-management`
   * **Application URL:** Choose your domain or subdomain (e.g., `seo.yourdomain.com`)
   * **Application startup file:** `server.js`
3. Click **Create**.
4. Copy the **"Enter to the virtual environment"** command shown at the top of the cPanel Node.js App page (it looks like `source /home/USER/nodevenv/seo-management/20/bin/activate && cd /home/USER/seo-management`).

---

## 6. Install Dependencies, Push DB Schema & Build

Open **cPanel Terminal** (or SSH), activate the Node.js virtual environment from Step 5, and run:

```bash
# 1. Activate cPanel's Node.js virtual environment (use the exact path from cPanel)
source /home/YOUR_CPANEL_USER/nodevenv/seo-management/20/bin/activate
cd ~/seo-management

# 2. Install dependencies
npm install

# 3. Push the Drizzle schema to your cPanel MySQL database
npx drizzle-kit push

# 4. Build Next.js for production
npm run build
```

> **Tip:** If `npm run build` hits a memory limit on shared hosting, run:
> `NODE_OPTIONS="--max-old-space-size=2048" npm run build`

---

## 7. Start the App

1. Return to **cPanel → Setup Node.js App**.
2. Also add your environment variables in the **Environment Variables** section of that cPanel page if your host does not automatically load `.env` into Passenger (`DATABASE_URL`, `AI_PROVIDER`, `GEMINI_API_KEY`, `GEMINI_MODEL`, `NODE_ENV=production`).
3. Click **Restart** on the application.
4. Visit your configured URL (e.g., `https://seo.yourdomain.com`).

---

## 8. Updating Later

Whenever new changes are pushed to GitHub:
```bash
source /home/YOUR_CPANEL_USER/nodevenv/seo-management/20/bin/activate
cd ~/seo-management
git pull origin main
npm install
npx drizzle-kit push
npm run build
```
Then click **Restart** in **cPanel → Setup Node.js App**.
