# Deploying to cPanel — step by step

This assumes a typical shared-hosting cPanel account. Screens vary slightly
between hosts, but every host running cPanel has the icons named below.

## 0. Before you start

- Know your **domain or subdomain** this site will live on (e.g.
  `jobs.example.com`, or your main domain).
- Have the project files ready as a zip (everything in this
  `sigma-recruitment-php/` folder — you can zip the whole folder as-is).

## 1. Create the MySQL database

1. In cPanel, open **MySQL® Databases**.
2. Under "Create New Database," enter a name (e.g. `sigma`) and create it.
   cPanel will prefix it with your cPanel username, e.g. `myuser_sigma` —
   that full prefixed name is what you'll put in `.env` as `DB_NAME`.
3. Under "MySQL Users → Add New User," create a user with a strong
   password. Note the full username (also prefixed, e.g. `myuser_sigma`)
   and the password.
4. Under "Add User To Database," add that user to the database you just
   created, and grant **ALL PRIVILEGES**.

## 2. Import the schema

1. Open **phpMyAdmin** from cPanel.
2. Select your new database in the left sidebar.
3. Click the **Import** tab, choose `database/schema.sql` from this
   project, and click **Go**.
4. You should see 7 new tables appear: `users`, `companies`, `jobs`,
   `jobseeker_profiles`, `experiences`, `educations`, `applications`.

## 3. Upload the files

1. In cPanel, open **File Manager**.
2. Decide where the project root will live. Two options:

   **Option A — custom document root (cleanest, if your host allows it):**
   Upload and extract the whole `sigma-recruitment-php` folder *outside*
   `public_html` — e.g. directly in your home directory, so you end up with
   `~/sigma-recruitment-php/public`, `~/sigma-recruitment-php/app`, etc.
   Then go to cPanel's **Domains** icon, find the domain/subdomain you're
   using, and set its **Document Root** to
   `sigma-recruitment-php/public`. Skip to step 4 — no file shuffling or
   code changes needed.

   **Option B — public_html only (works everywhere, including hosts that
   don't let you change the document root):**
   1. Upload the zip into your home directory (one level above
      `public_html`) and extract it there, so you get
      `~/sigma-recruitment-php/`.
   2. Move (not copy) everything **inside** `sigma-recruitment-php/public/`
      up into `public_html/` — so `public_html/index.php`,
      `public_html/.htaccess`, `public_html/assets/`, and
      `public_html/uploads/` all exist directly under `public_html`.
   3. Leave `app/`, `config/`, `database/`, `.env.example`, and the two
      `.md` files inside `~/sigma-recruitment-php/` (now missing its
      `public/` subfolder) — they must **not** be inside `public_html`,
      so they're never reachable from the web.
   4. Open `public_html/index.php` and change the one line:
      ```php
      define('BASE_PATH', dirname(__DIR__));
      ```
      to point at wherever you left `app/`/`config`/`database`, e.g.:
      ```php
      define('BASE_PATH', $_SERVER['HOME'] . '/sigma-recruitment-php');
      ```
      (`$_SERVER['HOME']` is your cPanel account's home directory — this
      works whether that's `/home/username` or something else, since the
      literal path is never hardcoded.)

   If you're not sure which option your host supports, try Option A first
   — if the Domains page has no "Document Root" field to edit, use Option B.

## 4. Configure `.env`

1. In File Manager (or via an SFTP client), find `.env.example` next to
   `config/` and duplicate it, renaming the copy to `.env` — the leading
   dot matters, and File Manager may hide dotfiles by default (toggle
   "Show Hidden Files" in Settings if you don't see it after creating it).
2. Edit `.env` and fill in:
   - `DB_NAME`, `DB_USER`, `DB_PASS` — from step 1.
   - `DB_HOST` — almost always `localhost` on shared cPanel hosting.
   - `APP_URL` — your site's full URL, no trailing slash.
   - `APP_KEY` — replace with any long random string (mash the keyboard).
   - `SEED_ADMIN_EMAIL` / `SEED_ADMIN_PASSWORD` — the admin login the seed
     script will create. **Pick a real password now**, not the example one.

## 5. Set upload folder permissions

The app needs to write resume/photo uploads to `public/uploads/` (or
`public_html/uploads/` if you used Option B).

1. In File Manager, right-click `uploads` → **Permissions**.
2. Set it to `755` (or `775` if `755` gives upload errors — some hosts run
   PHP as a different user than the file owner). Do the same for the
   `resumes` and `photos` subfolders if they exist.

## 6. Run the seed script

This creates your real admin login plus a few demo companies/jobs/applications
so you have something to look at immediately.

**If your plan includes Terminal** (cPanel → Advanced → Terminal, or check
if SSH is enabled): 
```bash
cd ~/sigma-recruitment-php   # wherever app/ and database/ ended up
php database/seed.php
```

**If you don't have Terminal/SSH access:** most cPanel plans also have a
**Cron Jobs** tool that can run a one-off PHP command even without a shell —
add a job like `php /home/USERNAME/sigma-recruitment-php/database/seed.php`
set to run once a few minutes out, then delete the cron job after it fires
(check its output via the email cPanel sends for cron output, or a log file
you redirect to). As a last resort, you can temporarily add
`ALLOW_WEB_SEED=true` to `.env`, visit `https://yoursite.com/../database/seed.php`
— actually since `database/` isn't inside your web root in either deployment
option above, this fallback only works if you deliberately place a copy of
`seed.php` inside `public/` temporarily; do that, load it once in your
browser, then delete that copy and remove `ALLOW_WEB_SEED` from `.env`.

You only need to run this once — it's safe to re-run (it skips anything
that already exists) but there's no reason to after the first time.

## 7. Verify it's live

1. Visit your domain — you should see the Sigma Recruitment home page with
   the seeded jobs and companies.
2. Log in as the admin (the email/password you set in step 4) at
   `/login`, and confirm the admin dashboard loads.
3. Log in as the seeded job seeker (`jane.doe@example.com` /
   `JobSeeker123!`) to see a filled-in profile and an application.
4. Log in as the seeded company portal user
   (`careers@novasoftware.example` / `CompanyPortal123!`) to see the
   company portal.

## 8. Before real users touch it

- **Change or remove the demo accounts.** The seeded job seeker and company
  portal login are for demoing the app to yourself — delete those rows (or
  change their passwords) via phpMyAdmin before going live with real users,
  and change the admin password from whatever you seeded it with.
- **Turn PHP error display off in production.** `.env`'s `APP_ENV=production`
  already does this (`config/config.php` only shows detailed errors when
  `APP_ENV` isn't `production`) — just make sure you didn't leave it set to
  something else.
- **Enable HTTPS.** Most cPanel hosts offer a free AutoSSL certificate under
  **SSL/TLS Status** — turn it on, then make sure `APP_URL` in `.env` uses
  `https://`. Once HTTPS is on, session cookies automatically get the
  `Secure` flag (see `app/bootstrap.php`).
- **Back up the database regularly.** cPanel's **Backup Wizard** can do
  this on a schedule — MySQL is your only data store now, so a DB backup is
  a full backup (plus the `uploads/` folder for resumes/photos).

## Troubleshooting

- **500 error / blank page on every URL except the home page** — almost
  always `.htaccess`/`mod_rewrite` not being picked up. Confirm
  `public/.htaccess` (or `public_html/.htaccess` under Option B) made it
  into the upload, and that your host has `mod_rewrite` enabled (cPanel
  hosts do by default; ask support if in doubt).
- **"Database connection failed"** — double check `DB_HOST`/`DB_NAME`/
  `DB_USER`/`DB_PASS` in `.env` match exactly what cPanel's MySQL Databases
  page shows (including the account-name prefix on both the DB name and
  username).
- **Uploads fail / "Could not save the uploaded file"** — the `uploads`
  folder (and its `resumes`/`photos` subfolders) aren't writable; redo step 5.
- **Changes to `.env` don't seem to take effect** — there's no cache to
  clear, but double-check you edited the `.env` that's actually a sibling
  of `config/` (not `.env.example`, and not a stray copy left in `public/`).
