# cPanel Deployment — Noble Collectable

Deploy your WordPress store directly to cPanel hosting using Git.

---

## Option 1: Manual Deployment (Step-by-Step)

### Prerequisites
- cPanel hosting account with:
  - PHP 8.0+ (check via cPanel)
  - MySQL 5.7+ (included)
  - Git support (most hosts have this)
  - AutoSSL (most hosts have this)

### Step 1: Create Domain/Addon Domain in cPanel

1. **Log into cPanel**
2. **Domains** or **Addon Domains** (depends on your host)
3. **Create New Domain:**
   - Domain: `noblecollectable.com` (or your domain)
   - Document Root: `public_html/noblecollectable` (or just `public_html/` if primary)
   - Click **Create**

### Step 2: Create MySQL Database

1. **cPanel → MySQL Databases**
2. **Create New Database:**
   - Database Name: `noblecollectable_db`
   - Click **Create**
3. **Create New User:**
   - Username: `noblecoll_user`
   - Password: (generate strong password, save it!)
   - Click **Create**
4. **Add User to Database:**
   - Select user and database
   - Check **All Privileges**
   - Click **Make Changes**

**Save credentials:**
```
Database: noblecollectable_db
User: noblecoll_user
Password: [your-password]
Host: localhost
```

### Step 3: Enable SSH Access

1. **cPanel → SSH Access** (or Terminal)
2. If disabled, click **Manage SSH Keys**
3. Generate public/private key pair (if needed)
4. Note your SSH command (e.g., `ssh yousha@your-cpanel-host.com`)

### Step 4: Deploy via Git (Recommended)

SSH into your server:

```bash
ssh yousha@your-cpanel-host.com
```

Navigate to public_html:

```bash
cd public_html/noblecollectable
# or cd public_html/ if primary domain
```

Clone the project:

```bash
git clone https://github.com/yousha/noblecollectable.git .
# or git clone git@github.com:yousha/noblecollectable.git . (if SSH key set up)
```

If repo is private, you'll need to set up GitHub credentials:

```bash
git config --global user.email "your-email@example.com"
git config --global user.name "Your Name"
```

### Step 5: Set File Permissions

```bash
cd public_html/noblecollectable

# Set WordPress directory ownership
chmod -R 755 wp-content/
chmod -R 755 wp-content/uploads/
chmod -R 755 wp-content/plugins/
chmod -R 755 wp-content/themes/

# Set config file
chmod 644 wp-config.php
```

### Step 6: Download and Configure WordPress

Download WordPress core files:

```bash
# If not included in git repo, download WordPress
wget https://wordpress.org/latest.tar.gz
tar xzf latest.tar.gz
# Copy WordPress files to your directory
# Or use wp-cli (if available):
wp core download --allow-root
```

### Step 7: Create wp-config.php

```bash
cp wp-config-sample.php wp-config.php
```

Edit `wp-config.php`:

```bash
nano wp-config.php
```

Update these lines with your database credentials:

```php
define('DB_NAME', 'noblecollectable_db');
define('DB_USER', 'noblecoll_user');
define('DB_PASSWORD', 'your-password-here');
define('DB_HOST', 'localhost');
```

Add security keys (go to https://api.wordpress.org/secret-key/1.1/salt/ and paste):

```php
define('AUTH_KEY',         'paste-here...');
define('SECURE_AUTH_KEY',  'paste-here...');
define('LOGGED_IN_KEY',    'paste-here...');
define('NONCE_KEY',        'paste-here...');
```

Save file: `Ctrl+X`, then `Y`, then `Enter`

### Step 8: Enable HTTPS/SSL

1. **cPanel → Auto SSL** or **SSL/TLS**
2. **Issue Certificate** or **Auto SSL**
3. Wait 10–15 minutes for certificate to generate

### Step 9: Run WordPress Installation

Open your browser:

```
https://noblecollectable.com
```

(or your domain)

Complete WordPress setup:
- Site title: "Noble Collectable"
- Admin username & password
- Admin email

### Step 10: Install Plugins via WP-CLI (if available)

If your host has WP-CLI:

```bash
# SSH to server, navigate to domain root
wp plugin install woocommerce --activate --allow-root
wp plugin install polylang --activate --allow-root
wp plugin install woo-stripe-payment --activate --allow-root
wp plugin install wp-smushit --activate --allow-root
wp plugin activate noblecollectable-setup --allow-root
wp theme activate noblecollectable-child --allow-root
```

If WP-CLI not available, install plugins manually via WordPress admin.

### Step 11: Configure WooCommerce

Admin → **WooCommerce** → **Settings**:
- General: Set store address, currency (EUR)
- Shipping: Add zones (EU Standard €10, Express €20, Worldwide €25)
- Payments: Add Stripe live keys (switch from test mode)

### Step 12: Configure Email Notifications

Admin → **Settings** → **Email** (or WooCommerce Email settings):
- From address: info@noblecollectable.com
- Test: Place test order, verify confirmation received

---

## Option 2: Automated cPanel Deployment Script

If your host supports cPanel API, use this script:

```bash
bash cpanel-deploy.sh
```

(See below for script setup)

### Prerequisites for Script
- cPanel API token
- SSH access
- Git installed on server

### Create cPanel API Token

1. Log into cPanel
2. **Settings** → **API Tokens**
3. **Create Token**
4. Copy token (long string of characters)
5. Save to file: `~/.cpanel_token`

```bash
echo "your-api-token-here" > ~/.cpanel_token
chmod 600 ~/.cpanel_token
```

### Run Automated Script

```bash
bash cpanel-deploy.sh \
  --domain noblecollectable.com \
  --db-name noblecollectable_db \
  --db-user noblecoll_user \
  --db-password your-password \
  --cpanel-user your-cpanel-username
```

This script will:
- Create domain
- Create database
- Clone Git repo
- Configure WordPress
- Install plugins
- Activate theme
- Set permissions

---

## Post-Deployment Checklist

- [ ] Domain resolves to HTTPS (https://noblecollectable.com)
- [ ] SSL certificate valid (green padlock)
- [ ] WordPress admin accessible (https://noblecollectable.com/wp-admin)
- [ ] Shop page shows 10 products (https://noblecollectable.com/shop)
- [ ] Add to cart works
- [ ] Stripe payments configured (live keys, not test)
- [ ] Email notifications working (test order)
- [ ] Daily backups enabled (cPanel)

---

## Troubleshooting

### "WordPress Installation Failed"
- Verify database credentials in wp-config.php
- Check database is created in cPanel
- Verify MySQL user has all privileges

### "403 Forbidden"
- Check file permissions: `chmod 755 public_html/`
- Check .htaccess is readable

### "SSL Certificate Not Showing"
- Wait 15 minutes for AutoSSL to process
- Try forcing renewal via cPanel

### "Plugins Not Installing"
- Check PHP memory limit (at least 256MB)
- Admin → Settings → Debug, check error logs
- Use WP-CLI if admin panel fails

---

## Maintenance

### Regular Tasks
- **Daily:** cPanel backup (automated)
- **Weekly:** Check WordPress updates
- **Monthly:** Review Stripe transactions, orders
- **Quarterly:** Security audit, prune logs

### Update WordPress

Via cPanel SSH or Admin panel:

```bash
# SSH method
wp core update --allow-root
wp plugin update --all --allow-root
wp theme update --all --allow-root
```

Or via Admin → Dashboard → Updates

### Backup & Restore

**Backup:**
```bash
cPanel Backup feature → Download backup
# Or via SSH:
mysqldump -u noblecoll_user -p noblecollectable_db > backup.sql
tar czf wp-backup.tar.gz public_html/
```

**Restore:**
```bash
# Upload backup.sql and wp-backup.tar.gz via cPanel File Manager
mysql -u noblecoll_user -p noblecollectable_db < backup.sql
tar xzf wp-backup.tar.gz
```

---

## Support

- **WordPress:** https://wordpress.org/support/
- **WooCommerce:** https://docs.woocommerce.com/
- **Stripe:** https://stripe.com/docs
- **cPanel:** Contact your hosting provider

---

**Status:** Ready for deployment

Go to your cPanel hosting and follow **Option 1** or **Option 2** above.
