# KheloPakistan - cPanel Deployment Guide

## Prerequisites
- cPanel hosting with PHP 8.2+
- MySQL database
- SSH access (optional but recommended)
- Domain name

---

## Step 1: Prepare cPanel

### 1.1 Create MySQL Database
1. Login to cPanel
2. Go to **MySQL Databases**
3. Create new database (e.g., `username_khelopak`)
4. Create database user (e.g., `username_khelouser`)
5. Set a strong password
6. Add user to database with **ALL PRIVILEGES**
7. **Note down:**
   - Database name
   - Database username
   - Database password

### 1.2 Upload Database
1. Go to **phpMyAdmin** in cPanel
2. Select your database
3. Click **Import** tab
4. Upload `shop.sql` file from the project
5. Click **Go** to import

---

## Step 2: Upload Files

### Method A: File Manager (Easier)
1. Go to **File Manager** in cPanel
2. Navigate to `public_html/` (or your domain's directory)
3. Upload the entire project ZIP file
4. Extract the ZIP file
5. Move all files from `install/` folder to the root of `public_html/`

### Method B: FTP (Faster for large files)
1. Use FileZilla or any FTP client
2. Connect using cPanel FTP credentials
3. Upload all files to `public_html/`

---

## Step 3: Configure Environment

### 3.1 Update .env File
1. In File Manager, locate `.env` file
2. Right-click → Edit
3. Update these values:

```env
APP_ENV=production
APP_DEBUG=false
APP_URL="https://yourdomain.com"

DB_DATABASE="username_khelopak"
DB_USERNAME="username_khelouser"
DB_PASSWORD="your_database_password"

MAIL_HOST="mail.yourdomain.com"
MAIL_USERNAME="noreply@yourdomain.com"
MAIL_PASSWORD="your_email_password"
MAIL_FROM_ADDRESS="noreply@yourdomain.com"

FORCE_HTTPS="On"
```

4. Save the file

---

## Step 4: Set Permissions

### Via File Manager:
1. Select these folders:
   - `storage/`
   - `bootstrap/cache/`
   - `public/uploads/`
2. Right-click → **Permissions**
3. Set to **755** for directories
4. Set to **644** for files

### Via SSH (If available):
```bash
cd public_html
chmod -R 755 storage bootstrap/cache public/uploads
chmod -R 644 storage bootstrap/cache public/uploads
find storage -type d -exec chmod 755 {} \;
find storage -type f -exec chmod 644 {} \;
```

---

## Step 5: Configure Document Root

### Option A: Main Domain
If deploying to main domain (yourdomain.com):

1. **Move public folder contents to root:**
   - Copy all files from `public/` to `public_html/`
   - Update `index.php` to point to correct paths

2. **Update index.php:**
```php
require __DIR__.'/bootstrap/app.php';
// Change to:
require __DIR__.'/../bootstrap/app.php';
```

### Option B: Subdomain
1. In cPanel, go to **Subdomains**
2. Create subdomain (e.g., shop.yourdomain.com)
3. Set Document Root to: `/public_html/public`

### Option C: Addon Domain
1. In cPanel, go to **Addon Domains**
2. Add new domain
3. Set Document Root to point to `/public` folder

---

## Step 6: Optimize Laravel

### Via SSH:
```bash
cd public_html
php artisan config:cache
php artisan route:cache
php artisan view:cache
php artisan optimize
```

### Via Terminal in cPanel (if available):
Same commands as above

---

## Step 7: SSL Certificate

1. In cPanel, go to **SSL/TLS Status**
2. Select your domain
3. Click **Run AutoSSL** (for free Let's Encrypt SSL)
4. Or install custom SSL certificate

---

## Step 8: Test Deployment

1. Visit: `https://yourdomain.com`
2. Test:
   - Homepage loads correctly
   - Images display properly
   - Login to admin panel: `/admin`
   - Place a test order
   - Check email functionality

---

## Troubleshooting

### 500 Internal Server Error
- Check `.htaccess` file exists in public folder
- Verify storage permissions (755)
- Check error logs in cPanel

### Images Not Displaying
- Ensure `public/uploads/` has correct permissions
- Check `APP_URL` in `.env` matches your domain
- Run: `php artisan storage:link`

### Database Connection Error
- Verify database credentials in `.env`
- Ensure database user has privileges
- Check database host (usually `localhost`)

### White Screen / Blank Page
- Enable `APP_DEBUG=true` temporarily in `.env`
- Check storage logs: `storage/logs/laravel.log`
- Clear cache: `php artisan cache:clear`

---

## Security Recommendations

1. **Keep APP_DEBUG=false** in production
2. **Use strong database passwords**
3. **Enable FORCE_HTTPS="On"**
4. **Regularly update Laravel and packages**
5. **Backup database regularly**
6. **Protect .env file** (already in .htaccess)

---

## Admin Access

**Default Admin Login:**
- URL: `https://yourdomain.com/admin`
- Create admin during installation or check database `users` table

---

## Support

For issues, check:
- Laravel logs: `storage/logs/`
- cPanel error logs
- PHP error logs

---

**Deployed by:** Claude
**Date:** 2025-12-30
