# 🚀 cPanel Deployment Guide — DAV College
**Domain:** `davcollege.ovits.xyz`

---

## Pre-Deployment Checklist (Do on Your PC First)

- [ ] All changes saved and working locally
- [ ] `.env.cpanel.example` ready — rename and fill before uploading
- [ ] cPanel login credentials available
- [ ] MySQL database created in cPanel
- [ ] MySQL user created and assigned to the database with ALL PRIVILEGES

---

## Step 1 — PHP Version Setting (FIRST!)

> ⚠️ **IMPORTANT:** Go to **cPanel → MultiPHP Manager** and set the PHP version to **8.2** or **8.3** for `davcollege.ovits.xyz` before doing anything else. This project requires PHP 8.2+.

---

## Step 2 — Create Database in cPanel

1. Log in to **cPanel** → go to **MySQL Databases**
2. Create a new database: e.g., `dav_college`
   - cPanel auto-prefixes it: `cpanelusername_dav_college`
3. Create a new MySQL User with a strong password
   - cPanel auto-prefixes it: `cpanelusername_dbuser`
4. **Add the user to the database** → grant **ALL PRIVILEGES**
5. Note these values for your `.env`:
   - `DB_DATABASE` = `cpanelusername_dav_college`
   - `DB_USERNAME` = `cpanelusername_dbuser`
   - `DB_PASSWORD` = your chosen password
   - `DB_HOST` = `localhost` ← always use `localhost` on cPanel

---

## Step 3 — Prepare Your `.env` File

1. Open `.env.cpanel.example` from this project
2. Copy it, rename to `.env`
3. Fill in the DB values from Step 2
4. Generate a fresh APP_KEY:
   ```
   php artisan key:generate --show
   ```
   Copy the `base64:...` output → paste as `APP_KEY=` in your `.env`

Final `.env` must contain:
```
APP_NAME="DAV College"
APP_ENV=production
APP_KEY=base64:YOUR_GENERATED_KEY_HERE
APP_DEBUG=false
APP_URL=https://davcollege.ovits.xyz
LOG_LEVEL=error
DB_CONNECTION=mysql
DB_HOST=localhost
DB_DATABASE=cpanelusername_dav_college
DB_USERNAME=cpanelusername_dbuser
DB_PASSWORD=your_strong_password
SESSION_DRIVER=file
SESSION_DOMAIN=.davcollege.ovits.xyz
```

---

## Step 4 — Upload Files to cPanel

### Method A: File Manager ZIP (Recommended)
1. Zip your entire project folder (skip `.git/` and `node_modules/`)
2. In cPanel **File Manager** → go to `public_html/`
3. Upload the ZIP → Extract here

### Method B: FTP (FileZilla)
1. Connect with your cPanel FTP credentials
2. Upload all project files directly into `public_html/`

> ⚠️ The entire project root goes inside `public_html/`. The file `artisan` must be at `public_html/artisan`.

---

## Step 5 — Expected Folder Structure on Server

```
public_html/
├── .htaccess              ← root redirect (already configured)
├── .env                   ← your server-specific .env
├── artisan
├── app/
├── bootstrap/
│   └── cache/             ← must be writable (775)
├── config/
├── database/
├── public/
│   ├── .htaccess          ← Laravel URL rewriting
│   ├── index.php
│   ├── images/            ← career.jpg, cmat_form.jpeg, intro_cover_image.jpg
│   └── logos/             ← dav_logo.png, dav_logo_white.png
├── resources/
├── routes/
├── storage/               ← must be writable (775)
└── vendor/
```

---

## Step 6 — Set File Permissions

In **cPanel Terminal** (Advanced → Terminal):

```bash
cd public_html
chmod -R 775 storage
chmod -R 775 bootstrap/cache
chmod 755 public/images
chmod 755 public/logos
```

---

## Step 7 — Run Artisan Commands (cPanel Terminal)

```bash
cd public_html

# 1. Create all database tables
php artisan migrate --force

# 2. Clear old local caches + re-optimize for production
php artisan config:clear
php artisan route:clear
php artisan view:clear
php artisan cache:clear
php artisan optimize
```

> ⚠️ If cPanel Terminal is unavailable, use SSH (PuTTY) or contact your hosting provider.

---

## Step 8 — Post-Deployment Verification

| URL | Expected Result |
|-----|----------------|
| `https://davcollege.ovits.xyz/` | Home page loads with DAV logo and inquiry form |
| `/visit-form` | Visitor record form works |
| `/login` | Login page with DAV logo |
| `/signup` | **Redirects to login** (disabled — admin already exists) |
| `/admin/dashboard` | Redirects to login if not authenticated |
| After login → `/admin/entries` | Visitor records table |
| `/admin/settings/images` | Image upload panel (super admin only) |

---

## ⚠️ Common Issues & Fixes

### 500 Internal Server Error
- Temporarily set `APP_DEBUG=true` in `.env` to reveal the real error
- Check `storage/logs/laravel.log` for details
- Make sure `storage/` and `bootstrap/cache/` are writable

### Database Connection Failed
- Use `DB_HOST=localhost` (NOT `127.0.0.1`) on cPanel
- Double-check the database name includes the cPanel username prefix
- Verify user has ALL PRIVILEGES in MySQL Databases panel

### Images Not Loading
- Confirm files exist at `public/images/` : `career.jpg`, `cmat_form.jpeg`, `intro_cover_image.jpg`
- Run: `chmod 755 public/images/`

### Login / Sessions Not Working
- Confirm `SESSION_DOMAIN=.davcollege.ovits.xyz` (with leading dot)
- Run `php artisan config:clear` then `php artisan optimize` after every `.env` change

### 404 on All Routes (except home)
- Check `mod_rewrite` is enabled (cPanel → Apache Handlers)
- Make sure `public/.htaccess` is present and intact

---

## Files to NOT Upload to cPanel

| Item | Reason |
|------|--------|
| `.git/` | Version control — not needed on server |
| `node_modules/` | Not used — project uses CDN for CSS/JS |
| Your local `.env` | Server needs its own `.env` with cPanel DB credentials |
| `.env.cpanel.example` | Reference only — not needed on server |

---

*DAV College — davcollege.ovits.xyz — Production Deployment Reference*




Set PHP 8.2+ in cPanel MultiPHP Manager
Create MySQL database and user in cPanel → note the prefixed names
Copy .env.cpanel.example → .env and fill in your DB credentials
Run php artisan key:generate --show locally → paste key into server .env
Upload project (zip → upload to public_html/ → extract)
Set permissions: chmod -R 775 storage bootstrap/cache
Run in cPanel Terminal: php artisan migrate --force then php artisan optimize