# cPanel Deployment Instructions

## ✅ Issues Fixed
- **SYMLINK REMOVED**: The `public/storage` symlink has been removed and replaced with a real directory
- **Unnecessary files deleted**: 47+ .md documentation files removed
- **Development files cleaned**: Test scripts, SQL dumps, and Excel files removed

## 📦 How to Upload to cPanel

### Option 1: Using cPanel File Manager (Recommended for first-time)
1. **Compress your project** on Windows:
   - Right-click project folder → Send to → Compressed (zipped) folder
   
2. **Upload to cPanel**:
   - Login to cPanel
   - Open "File Manager"
   - Navigate to `public_html/` (or your domain folder)
   - Click "Upload" and select the zip file
   - Once uploaded, click "Extract"

3. **Important**: Move files OUT of the extracted folder into `public_html/`:
   - The Laravel `public/` folder contents should be in `public_html/`
   - All other folders (app, config, routes, etc.) should also be in the same level

### Option 2: Using FTP (FileZilla, etc.)
1. Connect to your cPanel FTP
2. Upload ALL files to your web root directory
3. Ensure proper structure (see below)

## 📁 Correct cPanel Structure

```
public_html/
├── .htaccess          (from public folder)
├── index.php          (from public folder)
├── favicon.ico        (from public folder)
├── app/
├── bootstrap/
├── config/
├── database/
├── resources/
├── routes/
├── storage/
├── vendor/
├── .env
└── artisan
```

## ⚙️ Post-Upload Configuration

### 1. Update .env File
Edit the `.env` file in cPanel File Manager:

```env
APP_ENV=production
APP_DEBUG=false
APP_URL=https://test.algopk.com

DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=your_cpanel_database_name
DB_USERNAME=your_cpanel_db_user
DB_PASSWORD=your_cpanel_db_password
```

### 2. Run Setup Script
In cPanel Terminal (or SSH):

```bash
cd /home/yourusername/public_html
bash cpanel-setup.sh
```

This script will:
- Set correct file permissions (755 for directories, 644 for files)
- Copy storage files to public/storage
- Clear and cache Laravel configuration
- Optimize the application

### 3. Manual Setup (if Terminal not available)

#### Set Permissions via File Manager:
- `storage/` folder: 775
- `bootstrap/cache/` folder: 775
- `.env` file: 644

#### Run Artisan Commands:
Create a temporary PHP file in `public_html/` called `setup.php`:

```php
<?php
require __DIR__.'/vendor/autoload.php';
$app = require_once __DIR__.'/bootstrap/app.php';
$kernel = $app->make(Illuminate\Contracts\Console\Kernel::class);

echo "Clearing caches...\n";
$kernel->call('config:clear');
$kernel->call('cache:clear');
$kernel->call('view:clear');
$kernel->call('route:clear');

echo "Caching configurations...\n";
$kernel->call('config:cache');
$kernel->call('route:cache');
$kernel->call('view:cache');

echo "Setup complete!";
```

Then visit: `https://test.algopk.com/setup.php` (delete after running)

## 🔐 Security Checklist

- ✅ Set `APP_DEBUG=false` in production
- ✅ Change `APP_KEY` (run `php artisan key:generate`)
- ✅ Ensure `.env` file is NOT publicly accessible
- ✅ Remove `setup.php` after running
- ✅ Disable directory listing in `.htaccess`

## 🚀 Testing Your Deployment

1. Visit your domain: `https://test.algopk.com`
2. Check if homepage loads
3. Test login/registration
4. Verify database connection
5. Test file uploads (images)

## 🐛 Troubleshooting

### White Screen / 500 Error
- Check `.env` database credentials
- Verify `storage/` and `bootstrap/cache/` have 775 permissions
- Check error logs in cPanel

### CSS/JS Not Loading
- Check `.htaccess` file exists in public folder
- Clear browser cache
- Verify `APP_URL` in `.env`

### Database Connection Error
- Verify database exists in cPanel MySQL Databases
- Check database user has ALL PRIVILEGES
- Confirm DB_HOST is `localhost` (not 127.0.0.1)

## 📞 Support
If issues persist, check:
1. cPanel Error Logs (in Metrics → Errors)
2. Laravel logs in `storage/logs/laravel.log`
3. PHP version (Laravel 10 requires PHP 8.1+)
