# Deploying InLynq on Namecheap (cPanel + Terminal)

About 20 minutes. Replace `yourdomain.com` with your domain.

Namecheap's Terminal is at **cPanel → Advanced → Terminal**. It opens in your home folder (`/home/USERNAME`).

---

## 1. Choose PHP 8.3

**cPanel → Software → Select PHP Version**

1. **Current PHP version:** choose **8.3** (8.4 also works) → **Set as current**.
2. **Extensions** tab: make sure these are ticked: `pdo_mysql`, `mysqlnd`, `mbstring`, `fileinfo`, `gd`, `curl`, `dom`, `xml`, `intl`, `zip`, `bcmath`.
3. **Options** tab: `memory_limit` 256M, `upload_max_filesize` 12M, `post_max_size` 12M.

Close and reopen Terminal afterwards so it uses the new version. Check with:

```bash
php -v
```

## 2. Create the database

**cPanel → Databases → MySQL® Databases**

1. **Create New Database:** `inlynq` → it becomes `USERNAME_inlynq`.
2. **Add New User:** `inlynq` with a strong password (use the generator) → `USERNAME_inlynq`.
3. **Add User To Database** → **ALL PRIVILEGES** → **Make Changes**.

## 3. Upload and extract

**cPanel → Files → File Manager** → open your home folder (the top level, **not** `public_html`) → **Upload** `inlynq-cpanel.zip`.

Then in Terminal:

```bash
cd ~
unzip -q inlynq-cpanel.zip && rm inlynq-cpanel.zip
ls inlynq
```

You should see `app`, `public`, `vendor`, `install.sh` and so on.

## 4. Point your domain at the app

**Main domain (`yourdomain.com`).** Namecheap keeps the main domain's document root at `public_html`. Replace that folder with a link to the app's `public` folder:

```bash
cd ~
mv public_html public_html_backup_$(date +%F)
ln -s ~/inlynq/public ~/public_html
ls -la ~ | grep public_html
```

The last line should show `public_html -> /home/USERNAME/inlynq/public`. Your old `public_html` is kept as a backup folder. Delete it later if it held nothing you need.

> **Subdomain or addon domain instead?** (e.g. `app.yourdomain.com`) In **cPanel → Domains → Create A New Domain**, set the **Document Root** to `inlynq/public` and skip the commands above.
>
> **If the link doesn't work on your plan** (you get a 403 or "Forbidden"), undo it (`rm ~/public_html && mv ~/public_html_backup_* ~/public_html`) and follow **Option B** in `DEPLOY_CPANEL.md`.

## 5. Fill in `.env`

```bash
cd ~/inlynq
cp .env.cpanel .env
nano .env
```

Change every `CHANGE_ME`:

| Setting | Value |
|---|---|
| `APP_URL` | `https://yourdomain.com` |
| `DB_DATABASE` / `DB_USERNAME` | `USERNAME_inlynq` |
| `DB_PASSWORD` | the database password from step 2 |
| `MAIL_HOST` | `mail.yourdomain.com` (or the server shown under **Email Accounts → Connect Devices**) |
| `MAIL_USERNAME` / `MAIL_FROM_ADDRESS` | an email account you create in **cPanel → Email Accounts**, e.g. `hello@yourdomain.com` |
| `MAIL_PASSWORD` | that email account's password |
| `PAYSTACK_PUBLIC_KEY` / `PAYSTACK_SECRET_KEY` | your Paystack **test** keys for now |
| `SEED_ADMIN_EMAIL` / `SEED_ADMIN_PASSWORD` | your admin login |

Save in nano with **Ctrl+O**, **Enter**, then exit with **Ctrl+X**. Leave `APP_KEY` as it is; it's already generated.

## 6. Run the installer

```bash
cd ~/inlynq
bash install.sh
```

It checks PHP and extensions, refuses to run while any `CHANGE_ME` is left, creates the tables, sets up the plans and your admin account, caches everything, and prints your **cron line**. If it stops, it tells you exactly what to fix. Fix it, then run it again.

## 7. Add the cron job

**cPanel → Advanced → Cron Jobs** → **Common Settings: Once Per Minute (\* \* \* \* \*)** → paste the line `install.sh` printed. It looks like:

```
cd /home/USERNAME/inlynq && /usr/local/bin/php artisan schedule:run >> /dev/null 2>&1
```

This runs emails, Paystack webhook processing, image thumbnails and analytics. If your plan only allows longer intervals, use the shortest available. Everything still works, just with a delay.

## 8. HTTPS

**cPanel → Security → SSL/TLS Status** → tick your domain → **Run AutoSSL**. If Namecheap's SSL plugin is on your account, it may already be issued.

Visit **https://yourdomain.com**. You should see the InLynq landing page. Log in at `/login` with your admin details. The admin area is `/admin`.

## 9. Paystack

1. Paystack dashboard → **Settings → API Keys & Webhooks**.
2. **Test Webhook URL:** `https://yourdomain.com/webhooks/paystack`.
3. Register a normal account on your site → **Billing → Upgrade** → pay with a Paystack test card. Within about a minute, **Billing** should show the plan as **Active**.
4. When ready for real money, put the **live** keys in `.env`, set the **Live Webhook URL** to the same address, then run:

```bash
cd ~/inlynq && php artisan optimize
```

## Updating later

On your computer: `bash deploy/build-cpanel.sh`, then upload the new `inlynq-cpanel.zip` to your home folder. Then in Terminal:

```bash
cd ~ && unzip -oq inlynq-cpanel.zip && rm inlynq-cpanel.zip
cd ~/inlynq && bash update.sh
```

Your `.env`, uploaded photos and logs are untouched.

## Handy commands

```bash
cd ~/inlynq
tail -n 50 storage/logs/laravel-$(date +%F).log   # recent errors
php artisan optimize                              # after editing .env
php artisan about                                 # environment summary
php artisan queue:work --stop-when-empty          # process waiting jobs now
php artisan down / php artisan up                 # maintenance mode
```

## If something goes wrong

| What you see | What to do |
|---|---|
| **500 error** | Run `tail -n 50 storage/logs/laravel-*.log`. Most often the DB password in `.env` is wrong. Run `php artisan optimize` after fixing it. |
| **403 Forbidden** on the homepage | The `public_html` link isn't allowed on your server. Use Option B in `DEPLOY_CPANEL.md`, or ask Namecheap support to point the main domain at `inlynq/public`. |
| Page has no styling | The domain isn't pointing at `inlynq/public` (step 4). |
| **419 Page expired** | `APP_URL` must exactly match the address you visit (https, with or without www). |
| Emails don't arrive | The cron job (step 7) isn't set, or the mail settings are wrong. Test with `php artisan queue:work --stop-when-empty` and check the log. |
| Payment stuck on "pending" | Check the webhook URL in Paystack. As admin, open `/admin/payments` → the payment → **Re-verify with Paystack**. |
