# Production Server Deployment Guide

## 🔴 Current Issue: Database Connection Error

Your production server at `/home/admin254/Inventory/` is showing:
```
Error: Database connection not set
```

This is a **server-side issue**, not a code problem.

## 🎯 Step-by-Step Fix

### Step 1: Upload server_diagnostic.php to Your Server

Upload the file `server_diagnostic.php` to your production server root directory:
```
/home/admin254/Inventory/server_diagnostic.php
```

### Step 2: Run the Diagnostic

Via SSH:
```bash
cd /home/admin254/Inventory
php server_diagnostic.php
```

OR via browser:
```
https://portal.myeducationforlife.net/server_diagnostic.php
```

This will tell you exactly what's missing.

## 🔧 Most Likely Issues & Fixes

### Issue 1: pdo_mysql Extension Missing (Most Common)

**Symptoms:** Diagnostic shows "pdo_mysql: ✗ NOT LOADED"

**Fix Options:**

**A. cPanel/WHM Access:**
1. Log into WHM/cPanel
2. Go to "Software" → "EasyApache 4"
3. Search for "mysql" or "pdo"
4. Enable these packages:
   - `ea-php81-php-pdo` (or your PHP version)
   - `ea-php81-php-mysqlnd`
5. Click "Provision" to apply changes

**B. Contact Hosting Provider:**
Send them this request:

```
Subject: Please Enable PHP pdo_mysql Extension

Hello,

I need the pdo_mysql PHP extension enabled for my account:
- Domain: portal.myeducationforlife.net
- Path: /home/admin254/Inventory
- Current PHP Version: [check from diagnostic]

Could you please enable the php-pdo and php-mysqlnd extensions?

Thank you!
```

**C. If You Have Root/SSH Access:**

For Ubuntu/Debian:
```bash
sudo apt-get update
sudo apt-get install php-mysql php-pdo
sudo systemctl restart apache2  # or nginx
```

For CentOS/RHEL:
```bash
sudo yum install php-mysqlnd php-pdo
sudo systemctl restart httpd  # or nginx
```

### Issue 2: .env File Not on Server

**Check if .env exists:**
```bash
ls -la /home/admin254/Inventory/.env
```

**If missing, create it:**
```bash
cd /home/admin254/Inventory
nano .env
```

**Add these contents (use your actual credentials):**
```env
APP_NAME="Education for Life ERP"
APP_ENV=production
APP_DEBUG=false
APP_URL=https://portal.myeducationforlife.net

DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=admin254_invento
DB_USERNAME=admin254_invento
DB_PASSWORD=your_actual_password

CACHE_DRIVER=file
SESSION_DRIVER=file
SESSION_LIFETIME=120
LOG_CHANNEL=daily
LOG_LEVEL=error
```

**Set proper permissions:**
```bash
chmod 644 .env
chown yourusername:yourusername .env
```

### Issue 3: Database Doesn't Exist

**Create database via cPanel:**
1. Go to MySQL Databases
2. Create database (e.g., `admin254_invento`)
3. Create user with strong password
4. Add user to database with ALL PRIVILEGES
5. Import `project.sql` via phpMyAdmin

**Or via command line:**
```bash
mysql -u root -p
CREATE DATABASE admin254_invento CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
GRANT ALL PRIVILEGES ON admin254_invento.* TO 'admin254_invento'@'localhost' IDENTIFIED BY 'your_password';
FLUSH PRIVILEGES;
exit;

# Import schema
mysql -u admin254_invento -p admin254_invento < project.sql
```

### Issue 4: Wrong Permissions

```bash
cd /home/admin254/Inventory

# Fix storage permissions
chmod -R 775 storage
chmod -R 775 bootstrap/cache

# Set ownership (replace 'username' with your user)
chown -R username:username storage
chown -R username:username bootstrap/cache

# If using Apache
chown -R www-data:www-data storage
chown -R www-data:www-data bootstrap/cache
```

## 📤 Files to Upload to Production

Make sure these are on your server:

1. ✅ All application files (via FTP/Git)
2. ✅ `.env` file with correct production credentials
3. ✅ `vendor/` folder (run `composer install --no-dev` on server)
4. ✅ Database imported (`project.sql`)

## ✅ Verification Checklist

After fixes, verify:

```bash
# 1. Check PHP extensions
php -m | grep pdo_mysql

# 2. Test database connection
php server_diagnostic.php

# 3. Check .env exists
cat .env | grep DB_

# 4. Check database tables
mysql -u admin254_invento -p admin254_invento -e "SHOW TABLES;"

# 5. Check admin user
mysql -u admin254_invento -p admin254_invento -e "SELECT username, email FROM users WHERE username='admin';"
```

## 🔐 Admin Login After Setup

Once everything is working:

- **URL:** https://portal.myeducationforlife.net
- **Username:** admin
- **Password:** admin123

## 📝 Production Best Practices

1. **Security:**
   ```bash
   # Remove diagnostic file after use
   rm server_diagnostic.php
   
   # Set proper .env permissions
   chmod 640 .env
   ```

2. **Caching:**
   ```bash
   php artisan config:cache
   php artisan route:cache
   ```

3. **Logs:**
   Monitor logs at: `/home/admin254/Inventory/storage/logs/`

## 🆘 Still Not Working?

1. Check web server error logs:
   ```bash
   tail -f /var/log/apache2/error.log
   # or
   tail -f /var/log/nginx/error.log
   ```

2. Check Laravel logs:
   ```bash
   tail -f storage/logs/laravel.log
   ```

3. Enable debug mode temporarily to see full error:
   - Edit `.env`: Set `APP_DEBUG=true`
   - View the error in browser
   - Set back to `false` when done

---

**The most common issue is missing pdo_mysql extension on shared hosting. Contact your hosting provider if needed!**
