# ✅ cPanel Deployment Checklist for test.algopk.com

## 📋 PRE-UPLOAD VERIFICATION

Run the verification script first:
```bash
verify-before-upload.bat
```

### Manual Checks:

- [ ] `public\storage` is a **real directory** (not symlink)
- [ ] `.env` file exists with correct settings
- [ ] `vendor` folder exists (run `composer install` if missing)
- [ ] No symlinks anywhere in project
- [ ] All unnecessary .md/.txt files removed
- [ ] Test files (test_*.php) removed

---

## 🚀 STEP-BY-STEP DEPLOYMENT TO test.algopk.com

### Step 1: Prepare the Project

```bash
# Run the verification
verify-before-upload.bat

# If symlink exists, fix it
fix-symlink-permanently.bat
```

### Step 2: Create ZIP Archive

**Windows:**
1. Right-click on `testapp` folder
2. Send to → Compressed (zipped) folder
3. Name it: `testapp.zip`

**Alternative (PowerShell):**
```powershell
Compress-Archive -Path "D:\INSTALLED SOFTWARE\htdocs\testapp\*" -DestinationPath "D:\testapp.zip"
```

### Step 3: Access cPanel

1. Login to cPanel: `https://algopk.com:2083` or your cPanel URL
2. Go to **File Manager**
3. Navigate to the subdomain directory (likely `public_html/test/` or `test.algopk.com/`)

### Step 4: Upload & Extract

1. Click **Upload** button
2. Select `testapp.zip`
3. Wait for upload to complete
4. Right-click ZIP → **Extract**
5. Extract to current directory

### Step 5: Restructure Files (CRITICAL!)

**Important:** Laravel's `public/` folder contents must be in the web root.

**Option A: If extracted to `public_html/test/testapp/`:**
```
Move everything from:
  public_html/test/testapp/
To:
  public_html/test/
```

**Option B: Correct structure should be:**
```
public_html/test/               (or test.algopk.com/)
├── .htaccess                   (from public folder)
├── index.php                   (from public folder)
├── favicon.ico                 (from public folder)
├── css/                        (from public folder)
├── js/                         (from public folder)
├── storage/                    (from public folder - REAL DIRECTORY!)
├── app/
├── bootstrap/
├── config/
├── database/
├── resources/
├── routes/
├── storage/                    (Laravel storage folder)
├── vendor/
├── .env
├── artisan
└── composer.json
```

### Step 6: Configure .env File

Edit `.env` in cPanel File Manager:

```env
APP_NAME="Your App Name"
APP_ENV=production
APP_DEBUG=false
APP_URL=https://test.algopk.com

DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=algopk_testdb          # Your cPanel database name
DB_USERNAME=algopk_testuser        # Your cPanel database user
DB_PASSWORD=your_database_password # Your database password

MAIL_MAILER=smtp
MAIL_HOST=mail.algopk.com
MAIL_PORT=587
MAIL_USERNAME=info@algopk.com
MAIL_PASSWORD=Admin@9090           # Update with real password
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=info@algopk.com
```

**Important Settings:**
- Set `APP_DEBUG=false` for production
- Use correct database credentials from cPanel
- Update `APP_URL` to match your subdomain

### Step 7: Set Permissions

In cPanel Terminal (or SSH):

```bash
cd /home/username/public_html/test

# Set directory permissions
find . -type d -exec chmod 755 {} \;

# Set file permissions
find . -type f -exec chmod 644 {} \;

# Critical folders need write access
chmod -R 775 storage
chmod -R 775 bootstrap/cache

# Protect .env
chmod 644 .env
```

### Step 8: Run Setup Script

```bash
cd /home/username/public_html/test
bash cpanel-setup.sh
```

**If Terminal/SSH not available**, create `setup-cpanel.php` in web root:

```php
<?php
// Temporary setup file - DELETE after running
require __DIR__.'/vendor/autoload.php';
$app = require_once __DIR__.'/bootstrap/app.php';
$kernel = $app->make(Illuminate\Contracts\Console\Kernel::class);

echo "<pre>";
echo "=== Laravel cPanel Setup ===\n\n";

echo "Clearing caches...\n";
$kernel->call('config:clear');
$kernel->call('cache:clear');
$kernel->call('view:clear');
$kernel->call('route:clear');

echo "Optimizing application...\n";
$kernel->call('config:cache');
$kernel->call('route:cache');
$kernel->call('view:cache');

echo "\n✅ Setup complete!\n";
echo "DELETE this file now!\n";
echo "</pre>";
```

Visit: `https://test.algopk.com/setup-cpanel.php`  
Then **DELETE** the file immediately.

### Step 9: Verify Deployment

1. Visit: `https://test.algopk.com`
2. Check if homepage loads
3. Test login/registration
4. Check if database works
5. Test file uploads

---

## 🐛 TROUBLESHOOTING

### Error: "500 Internal Server Error"

**Solution:**
```bash
# Check Laravel logs
cat storage/logs/laravel.log

# Check cPanel error logs
cat error_log

# Verify permissions
chmod -R 775 storage bootstrap/cache
```

### Error: "No input file specified"

**Cause:** `.htaccess` missing or incorrect structure

**Solution:**
1. Ensure `public/.htaccess` is in web root
2. Contents should have:
```apache
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>
```

### Error: Database connection failed

**Solution:**
1. Verify database exists in cPanel → MySQL Databases
2. Check user has ALL PRIVILEGES on the database
3. Confirm credentials in `.env`
4. Use `localhost` not `127.0.0.1` for DB_HOST

### Error: CSS/JS not loading

**Solution:**
1. Check `APP_URL` in `.env` matches your domain
2. Run: `php artisan config:cache`
3. Clear browser cache
4. Check file permissions (644 for CSS/JS files)

### Error: Symlink still exists

**On server, run:**
```bash
# Check for symlinks
ls -la | grep "^l"

# If found, remove and create real directory
rm -f storage
mkdir -p storage

# Copy files
cp -r ../storage/app/public/* storage/
```

---

## 📊 POST-DEPLOYMENT CHECKLIST

After deployment, verify:

- [ ] Homepage loads at `https://test.algopk.com`
- [ ] No 500 errors in browser console
- [ ] CSS/JS loads correctly
- [ ] Database connection works (test login)
- [ ] File uploads work (test image upload)
- [ ] Email sending works (test registration email)
- [ ] All routes accessible
- [ ] No symlink errors in cPanel error log

---

## 🔐 SECURITY CHECKLIST

- [ ] `APP_DEBUG=false` in `.env`
- [ ] `.env` file has 644 permissions (not 777!)
- [ ] Deleted `setup-cpanel.php` if you created it
- [ ] `storage/` has 775 permissions (not 777!)
- [ ] Database password is strong
- [ ] Changed default `APP_KEY` (run `php artisan key:generate`)

---

## 📞 NEED HELP?

### Check Error Logs:
```bash
# cPanel error log (last 50 lines)
tail -n 50 /home/username/public_html/test/error_log

# Laravel log (last 50 lines)
tail -n 50 /home/username/public_html/test/storage/logs/laravel.log
```

### Test Commands:
```bash
# Test PHP version (should be 8.1+)
php -v

# Test Composer
composer --version

# Test Laravel
php artisan --version

# Test database connection
php artisan tinker
>>> DB::connection()->getPdo();
```

---

## ✅ SUCCESS INDICATORS

Your deployment is successful when:
- ✅ `https://test.algopk.com` loads without errors
- ✅ Login/registration works
- ✅ Database queries work
- ✅ File uploads save correctly
- ✅ No symlink errors in logs
- ✅ All CSS/JS loads properly

**Your project is now live on test.algopk.com!** 🎉
