# Quick Deploy Script for cPanel

## What This Does
Prepares your Laravel project for cPanel upload by:
1. Creating a deployment-ready structure
2. Generating proper .htaccess files
3. Creating index.php redirector for root access

## Usage

### Windows (PowerShell)
```powershell
# Run this in project root
.\deploy-prep.ps1
```

### Manual Steps
If you prefer manual preparation:

1. **Create deploy folder**
2. **Copy all files EXCEPT vendor/ and node_modules/**
3. **Create .htaccess for root protection**

---

## After Upload to cPanel

### Typical cPanel Structure
```
/home/username/
├── public_html/              # Web root (public access)
│   ├── index.php            # Laravel public/index.php content
│   ├── .htaccess            # Laravel public/.htaccess
│   ├── css/
│   ├── js/
│   ├── mb-frontend-dist/
│   └── ...                  # Other public assets
│
└── laravel-app/             # Application files (OUTSIDE public_html)
    ├── app/
    ├── bootstrap/
    ├── config/
    ├── database/
    ├── resources/
    ├── routes/
    ├── storage/
    ├── .env
    ├── composer.json
    └── ...
```

### Setup After Upload

1. **Upload Structure**
   - Upload entire project to `/home/username/laravel-app/`
   - Move `public/*` contents to `/home/username/public_html/`

2. **Edit public_html/index.php**
   Change line 24 from:
   ```php
   require __DIR__.'/../vendor/autoload.php';
   ```
   To:
   ```php
   require __DIR__.'/../laravel-app/vendor/autoload.php';
   ```
   
   Change line 38 from:
   ```php
   $app = require_once __DIR__.'/../bootstrap/app.php';
   ```
   To:
   ```php
   $app = require_once __DIR__.'/../laravel-app/bootstrap/app.php';
   ```

3. **Run install.php**
   - Visit `https://yourdomain.com/install.php`
   - Complete the web installer

4. **SSH Commands**
   ```bash
   cd /home/username/laravel-app
   composer install --no-dev --optimize-autoloader
   php artisan migrate
   ```

5. **Cleanup**
   - Delete `public_html/install.php`
   - Verify `.env` is secure

---

## Alternative: All-in-public_html (Shared Hosting)

If your hosting doesn't let you access parent directories:

1. Upload entire project to `public_html/`
2. Create `.htaccess` in `public_html/`:
```apache
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
```

3. Access via `https://yourdomain.com/public/install.php`

**Security Warning**: This exposes `.env` and config files. Only use on trusted/private servers.

---

## Subdomain Setup

Best practice for production:

1. Create subdomain in cPanel (e.g., `app.yourdomain.com`)
2. cPanel automatically creates `/home/username/app.yourdomain.com/`
3. Upload Laravel to `/home/username/app.yourdomain.com/`
4. Move `public/*` to subdomain root
5. No index.php edit needed (paths are relative)

---

## File Permissions After Upload

Set via cPanel File Manager or SSH:

```bash
# Application files
chmod -R 755 /home/username/laravel-app

# Storage and cache (writable)
chmod -R 775 /home/username/laravel-app/storage
chmod -R 775 /home/username/laravel-app/bootstrap/cache

# Environment file (secure)
chmod 644 /home/username/laravel-app/.env
```

---

## Testing Checklist

After deployment:

- [ ] Homepage loads without errors
- [ ] Admin panel accessible at `/admin/panel`
- [ ] Telegram notifications working
- [ ] Antibot system blocking bots
- [ ] Database connection successful
- [ ] Storage folder writable
- [ ] install.php deleted
- [ ] .env file not publicly accessible

---

## Common Issues

### "No input file specified"
- Check index.php path edits are correct
- Verify .htaccess exists in public_html/

### "Class not found"
- Run `composer dump-autoload` in laravel-app/
- Check vendor/ folder exists and is complete

### "Permission denied" for storage
- Set 775 permissions on storage/ recursively
- Some hosts require 777 (less secure)

### Blank page / no errors
- Enable debug in .env: `APP_DEBUG=true`
- Check storage/logs/laravel.log
- Check cPanel Error Log

---

## Production Optimization

After everything works:

```bash
# Cache config (faster loads)
php artisan config:cache
php artisan route:cache

# Optimize autoloader
composer dump-autoload --optimize --classmap-authoritative

# Disable debug
# Edit .env: APP_DEBUG=false
```

---

## Backup Strategy

Regular backups via cPanel:

1. **Database**: cPanel → phpMyAdmin → Export
2. **Captures**: Download `storage/captures/` folder
3. **Config**: Backup `.env` file
4. **Full Backup**: cPanel → Backup Wizard → Full Backup

Schedule automatic backups if your host supports it.

Done. Your project is cPanel-ready.
