# Laravel E-commerce Admin - Free cPanel Deployment Guide

## Prerequisites
- PHP 8.2+ (Laravel 12 requirement)
- MySQL 5.7+ or MariaDB 10.3+
- Composer (for local preparation)

## Recommended Free Hosting Options

### 1. GoogieHost (Recommended)
- **URL**: https://googiehost.com/freehosting.html
- **Features**: 1000MB SSD, 100GB bandwidth, SSL, MySQL, No ads
- **Note**: Check if PHP 8.2+ is available

### 2. AeonFree
- **URL**: https://aeonfree.com/
- **Features**: Unlimited bandwidth, PHP, MySQL, SSL, cPanel

### 3. 000webhost
- **URL**: https://www.000webhost.com/
- **Features**: 300MB storage, 3GB bandwidth, PHP, MySQL

## Important Note
Most free hosting providers only support PHP 7.x or PHP 8.0/8.1. Laravel 12 requires PHP 8.2+. 
If your free host doesn't support PHP 8.2+, you may need to:
1. Downgrade to Laravel 10 (supports PHP 8.1)
2. Use a paid hosting service
3. Use a free VPS trial (DigitalOcean, Vultr, etc.)

## Deployment Steps

### Step 1: Prepare Files Locally
```bash
# Install dependencies without dev packages
composer install --no-dev --optimize-autoloader

# Generate optimized autoload
composer dump-autoload --optimize

# Clear and cache config
php artisan config:clear
php artisan cache:clear
php artisan route:clear
php artisan view:clear
```

### Step 2: Create Deployment Package
1. Zip the entire `ecommerce-admin` folder
2. Exclude: `node_modules/`, `.git/`, `tests/`, `storage/logs/*`

### Step 3: Upload to cPanel
1. Login to your cPanel account
2. Go to File Manager
3. Navigate to `public_html` folder
4. Upload and extract the zip file

### Step 4: Configure Document Root
The Laravel `public` folder should be your document root. Two options:

**Option A: Move public contents**
1. Move all files from `public/` to `public_html/`
2. Move all other Laravel files to a folder above `public_html/` (e.g., `laravel/`)
3. Edit `public_html/index.php`:
```php
require __DIR__.'/../laravel/vendor/autoload.php';
require __DIR__.'/../laravel/bootstrap/env.php';
$app = require_once __DIR__.'/../laravel/bootstrap/app.php';
```

**Option B: Use .htaccess redirect (if subdomain)**
Create `.htaccess` in `public_html/`:
```apache
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
```

### Step 5: Configure Database
1. In cPanel, go to MySQL Databases
2. Create a new database (e.g., `yourusername_ecommerce`)
3. Create a database user with a strong password
4. Add user to database with ALL PRIVILEGES

### Step 6: Update .env File
Edit `.env` via File Manager:
```env
APP_ENV=production
APP_DEBUG=false
APP_URL=https://yourdomain.com

DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=yourusername_ecommerce
DB_USERNAME=yourusername_dbuser
DB_PASSWORD=your_secure_password
```

### Step 7: Run Migrations
If your host provides SSH access:
```bash
php artisan migrate --force
php artisan db:seed --force
```

If no SSH access, use the web-based migration route (add temporarily):
```php
// routes/web.php - REMOVE AFTER USE!
Route::get('/setup-database', function() {
    Artisan::call('migrate', ['--force' => true]);
    Artisan::call('db:seed', ['--force' => true]);
    return 'Database setup complete!';
});
```

### Step 8: Set Permissions
Via File Manager or SSH:
```bash
chmod -R 755 storage/
chmod -R 755 bootstrap/cache/
```

### Step 9: Generate Application Key
If needed, add this route temporarily:
```php
Route::get('/generate-key', function() {
    Artisan::call('key:generate');
    return 'Key generated!';
});
```

## Troubleshooting

### 500 Internal Server Error
1. Check `storage/logs/laravel.log` for errors
2. Ensure `.htaccess` is properly configured
3. Verify PHP version is 8.2+
4. Check file permissions

### Database Connection Error
1. Verify database credentials in `.env`
2. Check if database user has proper privileges
3. Ensure database host is `localhost` (not 127.0.0.1)

### Blank Page
1. Enable debug mode temporarily: `APP_DEBUG=true`
2. Check PHP error logs in cPanel
3. Verify all required PHP extensions are enabled

## Required PHP Extensions
- BCMath
- Ctype
- Fileinfo
- JSON
- Mbstring
- OpenSSL
- PDO
- Tokenizer
- XML
- cURL
