# Deployment guide — Luckus PHP site (cPanel / RackNerd / shared hosting)

This guide walks through deploying the Luckus B2B site to a typical cPanel-based shared host (tested on RackNerd). Total time: ~15 minutes.

---

## Prerequisites

- cPanel access (URL like `https://your-server.com:2083`)
- A MySQL/MariaDB database (you'll create it in cPanel)
- A domain pointed to the server (e.g. `topluckus.com`)
- Optional but recommended: SSL certificate (cPanel → SSL/TLS Status → AutoSSL)

---

## Step 1 — Create the MySQL database

In cPanel:

1. Go to **MySQL® Databases** (under "Databases")
2. **Create a new database**, e.g. `toplucku_luckus` (cPanel auto-prefixes your cPanel username)
3. **Create a new database user**, e.g. `toplucku_luckus` with a strong random password. **Save this password** — you'll need it in Step 4.
4. **Add the user to the database**, granting **ALL PRIVILEGES**
5. Note the full database name, username, and password for Step 4

---

## Step 2 — Upload the site files

### Option A — File Manager (simplest for small sites)

1. In cPanel, open **File Manager**
2. Navigate to `public_html/` (or the document root for your domain)
3. Click **Upload** and select the deployment zip file
4. Once uploaded, right-click the zip in File Manager and **Extract**
5. After extraction, **delete the zip file** (security)

### Option B — FTP (faster for large sites)

Use FileZilla, WinSCP, or your FTP client:

- **Host:** `your-server.com` (or the IP)
- **User/Pass:** your cPanel FTP credentials (create an FTP account under "FTP Accounts" if you don't have one)
- **Port:** 21
- **Protocol:** FTP (or FTPS for encryption)
- **Upload to:** `/public_html/`
- **Drag-and-drop** the unzipped site contents into `public_html/`

### File structure on the server after upload

Your `public_html/` should look like this (the **inner** `public/` of the project becomes the document root):

```
public_html/
├── .htaccess              ← (copied from project/public/.htaccess)
├── index.php
├── products.php
├── product.php
├── news.php
├── news-detail.php
├── inquiry.php
├── about.php
├── capabilities.php
├── contact.php
├── customization.php
├── admin/                  ← admin panel
├── assets/                 ← css, js, images (logo, QR, etc.)
├── uploads/                ← admin-uploaded images
└── (no sub-folder called "public")
```

**Important:** the contents of the project's `public/` folder go directly into `public_html/`. If your zip has a `public/` sub-folder, extract its contents **one level up** so the structure above is correct.

---

## Step 3 — Create the config file

In File Manager:

1. Navigate to `public_html/`
2. Find `config.sample.php`
3. Right-click → **Copy** → name it `config.php`
4. Right-click `config.php` → **Edit** (use Code Editor)
5. Update the `db` block:

```php
'db' => [
    'host'    => 'localhost',         // cPanel usually uses 'localhost'
    'port'    => 3306,
    'name'    => 'toplucku_luckus',   // ← your full database name (with cPanel prefix)
    'user'    => 'toplucku_luckus',   // ← your full database username
    'pass'    => 'YOUR_STRONG_DB_PASSWORD',  // ← the password from Step 1
    'charset' => 'utf8mb4',
],
```

6. Update `site.url` to your real domain:

```php
'site' => [
    'name'       => 'Luckus',
    'tagline'    => 'Trusted Charger & Cable Manufacturer',
    'url'        => 'https://topluckus.com',   // ← your real domain, NO trailing slash
    'admin_path' => '/admin',
    'env'        => 'production',               // ← change from 'development'
],
```

7. **Save** the file

---

## Step 4 — Run the installer

In your browser, visit:

```
https://topluckus.com/install.php
```

You should see:

```
Luckus installer
==============
[OK]   Connected to MySQL
[OK]   Schema applied (products / inquiries / admin_users / content_pages / posts / categories / site_settings)
[OK]   Seed data applied (18 products + content pages)

Status:
  products:     18
  inquiries:    0
  admin_users:  1
  pages:        4
  posts:        5
  categories:   13
  site_settings: 15

Done.
  Public site:   https://topluckus.com/
  Admin panel:   https://topluckus.com/admin/  (user: admin / pass: admin123)
```

**If you see any `[FAIL]`** — check the `db` block in `config.php` matches what cPanel showed you in Step 1. The cPanel prefixes your cPanel username to both the database name and username.

**If the installer says "0 products"** — that's fine, it just means the seed data didn't run. You can re-run `install.php` (it's idempotent) or seed manually:
- In cPanel → **phpMyAdmin** → select the database → **Import** → choose `sql/seed.sql` from the project zip → **Go**

---

## Step 5 — Secure the install

1. In File Manager, **delete** `public_html/install.php` (it shows DB credentials in its output and is no longer needed)
2. **Delete** `public_html/migrate-product-images.php` (optional — only useful if you ever had flat `uploads/products/` files to organize)
3. Confirm `public_html/config.php` is present and not world-readable: right-click → **Permissions** → set to `0640` (owner read, group read, others none)

---

## Step 6 — Set up SSL (https)

In cPanel:

1. Go to **SSL/TLS Status**
2. Find `topluckus.com` and `www.topluckus.com` in the list
3. Click **AutoSSL** (or **Run AutoSSL** if needed)
4. Wait ~1 minute for the cert to be issued by Let's Encrypt
5. Visit `https://topluckus.com` to confirm the green padlock

The `.htaccess` in `public_html/` has a commented-out HTTPS redirect block. Once SSL works, enable it:

1. Edit `public_html/.htaccess`
2. Find the section that starts `# RewriteCond %{HTTPS} off`
3. Uncomment those 2 lines (remove the `# `)
4. Save

Now all `http://` requests will redirect to `https://`.

---

## Step 7 — Change the admin password (CRITICAL)

The default admin login is `admin` / `admin123`. You **must** change this before the site goes public.

1. Log in at `https://topluckus.com/admin/login.php` with `admin` / `admin123`
2. In cPanel, open **phpMyAdmin**
3. Select the `toplucku_luckus` database
4. Click the **admin_users** table
5. Click **Edit** on the `admin` row
6. In the `password_hash` field, paste a new bcrypt hash. Generate one quickly by running this in your terminal:

   ```bash
   php -r "echo password_hash('YourNewStrongPassword', PASSWORD_BCRYPT) . PHP_EOL;"
   ```

7. Save
8. Log out and log back in with the new password

---

## Step 8 — Update site content via the admin panel

Once deployed, all content is editable from the admin panel at `https://topluckus.com/admin/`:

| What | URL |
|---|---|
| Update site name, logo, contact email, WhatsApp, footer copy | Website Setup |
| Add/edit product images and specs | Products → New Product / Edit |
| Edit the navigation dropdown (categories) | Categories |
| Add/edit news posts with cover images | News Posts → New Post |
| Edit static content pages (about, capabilities, etc.) | Content Pages |
| View and respond to incoming inquiries | Inquiries |

For details on how each section works, see the **PRD** (if provided) or the on-screen help text.

---

## Troubleshooting

### "500 Internal Server Error" on every page

- Check `public_html/.htaccess` exists and is uploaded correctly
- In cPanel → **Error Log** (under "Metrics") for the actual error message
- Most common cause: PHP version mismatch. The site requires PHP 8.0+. Check **MultiPHP Manager** in cPanel and switch the domain to PHP 8.2 or 8.3.

### "Database connection failed" or `[FAIL] SQLSTATE[HY000] [1045]`

- Wrong DB credentials in `config.php`. Double-check the cPanel "MySQL Databases" page for the exact database name (it has a prefix) and the exact username.

### "Page not found" on `/news/<slug>`

- The URL rewrite in `.htaccess` requires Apache's `mod_rewrite`. cPanel usually has it on by default. If not, ask your host or switch to LiteSpeed (RackNerd uses LiteSpeed by default and it supports `.htaccess`).

### Admin uploads give "Permission denied"

- `public_html/uploads/` and its subfolders (`products/`, `posts/`, `site/`) must be writable by PHP. Set permissions to `0755` and ownership to the cPanel user (not `root` or `nobody`).

### Images show "broken" icons in admin

- The image folder structure is correct. Right-click the image in File Manager → **Permissions** → `0644` (readable by all).

---

## Maintenance

- **Backups:** cPanel → **Backup Wizard** → generate a full backup weekly. Download and store offsite.
- **Updates:** the site has no Composer/npm dependencies, so "updates" = edit the PHP files directly and re-upload.
- **Database backups:** cPanel → **phpMyAdmin** → select the database → **Export** → Custom → save the `.sql` file offsite. Do this before any major content changes.

---

## Support

For deployment issues, contact the project owner.
For site-content questions, log in to `/admin/` and edit directly.
