# StarMeet - Namecheap Hosting Setup Guide

Complete guide for deploying StarMeet Laravel 11 application on Namecheap shared hosting.

## Table of Contents
- [Prerequisites](#prerequisites)
- [Namecheap Hosting Requirements](#namecheap-hosting-requirements)
- [Step-by-Step Deployment](#step-by-step-deployment)
- [Database Setup](#database-setup)
- [Environment Configuration](#environment-configuration)
- [Troubleshooting](#troubleshooting)

---

## Prerequisites

### Local Requirements
- Complete StarMeet Laravel 11 project files
- FTP client (FileZilla, Cyberduck) or cPanel File Manager
- SSH access (optional but recommended)

### Namecheap Hosting Requirements

#### Minimum Plan
- **Stellar / Stellar Plus** shared hosting plan
- PHP 8.2 or higher
- MySQL 5.7+ or MariaDB 10.3+
- SSH access (recommended)

#### Check PHP Version
1. Login to cPanel
2. Go to **Select PHP Version**
3. Ensure PHP 8.2 or 8.3 is selected
4. Enable required extensions (see below)

#### Required PHP Extensions
Make sure these extensions are enabled in cPanel:
- BCMath
- Ctype
- cURL
- DOM
- Fileinfo
- JSON
- Mbstring
- OpenSSL
- PDO
- PDO_MySQL
- Tokenizer
- XML
- ZIP

---

## Step-by-Step Deployment

### Step 1: Prepare Files Locally

Before uploading, prepare your Laravel application:

```bash
# Navigate to your project
cd /path/to/starmeet

# Install production dependencies
composer install --no-dev --optimize-autoloader

# Clear and cache configurations
php artisan config:cache
php artisan route:cache
php artisan view:cache

# Optimize autoloader
composer dump-autoload --optimize
```

### Step 2: Create Deployment Package

Create a clean deployment package:

```bash
# Create a deployment folder
mkdir starmeet-deploy

# Copy essential files
cp -r app bootstrap config database public resources routes storage starmeet-deploy/
cp artisan composer.json composer.lock .env.namecheap starmeet-deploy/
cp -r vendor starmeet-deploy/  # Or install on server
```

**Files NOT to upload:**
- `.env` (will create on server)
- `node_modules/` (not needed for production)
- `.git/` (if using git)
- Tests and development files

### Step 3: Upload Files to Namecheap

#### Option A: Using FTP (FileZilla)

1. **Get FTP Credentials:**
   - Login to cPanel
   - Go to **FTP Accounts**
   - Note your FTP username and server address

2. **Connect via FileZilla:**
   - Host: `yourdomain.com` or server IP
   - Username: Your cPanel username
   - Password: Your cPanel password
   - Port: 21

3. **Upload Files:**
   - Navigate to `public_html/` or subdomain folder
   - Upload all project files
   - **Important:** Upload `public/` folder contents to `public_html/`

#### Option B: Using cPanel File Manager

1. Login to cPanel
2. Open **File Manager**
3. Navigate to `public_html/`
4. Click **Upload**
5. Select and upload your files
6. Extract if uploading as ZIP

### Step 4: Set Up Directory Structure

Namecheap uses `public_html` as the web root. You have two options:

#### Option 1: Upload to Root (Recommended for primary domain)

```
/home/username/                    # cPanel home
├── starmeet/                      # Laravel app files
│   ├── app/
│   ├── bootstrap/
│   ├── config/
│   ├── database/
│   ├── resources/
│   ├── routes/
│   ├── storage/
│   └── vendor/
└── public_html/                   # Web root
    ├── .htaccess                  # Laravel rewrite rules
    ├── index.php                  # Entry point
    └── ... (other public assets)
```

**Setup:**
1. Upload Laravel files to `/home/username/starmeet/`
2. Upload `public/` contents to `/home/username/public_html/`
3. Modify `public_html/index.php` to point to correct path

#### Option 2: Use Subdomain

1. In cPanel, create a subdomain: `app.yourdomain.com`
2. This creates `/home/username/app.yourdomain.com/`
3. Upload all files there
4. Point subdomain document root to `app.yourdomain.com/public`

---

## Database Setup

### Step 1: Create MySQL Database

1. Login to cPanel
2. Go to **MySQL Database Wizard**
3. Create database:
   - Database name: `username_starmeet` (prefix auto-added)
4. Create database user:
   - Username: `username_starmeet`
   - Password: Generate strong password
5. Add user to database with **ALL PRIVILEGES**
6. **Save these credentials!**

### Step 2: Update Environment File

Create `.env` file in your Laravel root:

```env
APP_NAME=StarMeet
APP_ENV=production
APP_KEY=base64:YOUR_GENERATED_KEY_HERE
APP_DEBUG=false
APP_TIMEZONE=UTC
APP_URL=https://yourdomain.com

APP_LOCALE=en
APP_FALLBACK_LOCALE=en
APP_FAKER_LOCALE=en_US

APP_MAINTENANCE_DRIVER=file
APP_MAINTENANCE_STORE=database

BCRYPT_ROUNDS=12

LOG_CHANNEL=stack
LOG_STACK=single
LOG_DEPRECATIONS_CHANNEL=null
LOG_LEVEL=error

# Database Configuration (Namecheap)
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=username_starmeet
DB_USERNAME=username_starmeet
DB_PASSWORD=your_database_password

SESSION_DRIVER=file
SESSION_LIFETIME=120
SESSION_ENCRYPT=false
SESSION_PATH=/
SESSION_DOMAIN=null

BROADCAST_CONNECTION=log
FILESYSTEM_DISK=local
QUEUE_CONNECTION=sync

CACHE_STORE=file
CACHE_PREFIX=

MEMCACHED_HOST=127.0.0.1

REDIS_CLIENT=phpredis
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_MAILER=sendmail
MAIL_HOST=
MAIL_PORT=587
MAIL_USERNAME=
MAIL_PASSWORD=
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS="noreply@yourdomain.com"
MAIL_FROM_NAME="${APP_NAME}"

AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=
AWS_USE_PATH_STYLE_ENDPOINT=false

VITE_APP_NAME="${APP_NAME}"
```

### Step 3: Generate Application Key

Via SSH or create locally:

```bash
php artisan key:generate --show
```

Copy the generated key to your `.env` file.

### Step 4: Run Migrations

#### Option A: Via SSH (Recommended)

```bash
# SSH into your Namecheap account
ssh username@yourdomain.com

# Navigate to Laravel directory
cd /home/username/starmeet

# Run migrations
php artisan migrate --force

# Run seeders
php artisan db:seed --force
```

#### Option B: Via PHP Script

Create `migrate.php` in your Laravel root:

```php
<?php
require __DIR__ . '/vendor/autoload.php';
$app = require_once __DIR__ . '/bootstrap/app.php';
$kernel = $app->make(Illuminate\Contracts\Console\Kernel::class);
$kernel->bootstrap();
Artisan::call('migrate', ['--force' => true]);
Artisan::call('db:seed', ['--force' => true]);
echo "Migrations completed!";
```

Access via browser: `https://yourdomain.com/migrate.php`
**Delete this file after use!**

---

## Environment Configuration

### .htaccess Configuration

Create/Edit `.htaccess` in `public_html/`:

```apache
<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews -Indexes
    </IfModule>

    RewriteEngine On

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    # Redirect Trailing Slashes If Not A Folder
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]

    # Send Requests To Front Controller
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

# PHP Settings
<IfModule mod_php.c>
    php_value upload_max_filesize 64M
    php_value post_max_size 64M
    php_value max_execution_time 300
    php_value max_input_time 300
    php_value memory_limit 256M
</IfModule>

# Disable Directory Browsing
Options -Indexes

# Protect .env file
<Files .env>
    Order allow,deny
    Deny from all
</Files>

# Protect sensitive files
<FilesMatch "^\.">
    Order allow,deny
    Deny from all
</FilesMatch>
```

### public_html/index.php

```php
<?php

use Illuminate\Http\Request;

// Set the correct path to Laravel's public directory
define('LARAVEL_START', microtime(true));

// Adjust this path based on your server structure
$laravelPath = '/home/username/starmeet';

// Register the auto loader
require $laravelPath . '/vendor/autoload.php';

// Bootstrap Laravel and handle the request
(require_once $laravelPath . '/bootstrap/app.php')
    ->handleRequest(Request::capture());
```

**Replace `/home/username/starmeet` with your actual path!**

---

## Post-Deployment Setup

### 1. Set Folder Permissions

Via SSH or cPanel File Manager:

```bash
# Navigate to Laravel directory
cd /home/username/starmeet

# Set permissions
chmod -R 755 storage
chmod -R 755 bootstrap/cache
chmod -R 644 .env

# Create storage link (if not done)
php artisan storage:link
```

### 2. Clear and Cache Configurations

```bash
cd /home/username/starmeet

# Clear caches
php artisan cache:clear
php artisan config:clear
php artisan view:clear
php artisan route:clear

# Cache for production
php artisan config:cache
php artisan route:cache
php artisan view:cache
```

### 3. SSL Certificate (HTTPS)

1. In cPanel, go to **SSL/TLS**
2. Install free Let's Encrypt certificate
3. Force HTTPS in `.htaccess`:

```apache
# Force HTTPS
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
```

---

## Troubleshooting

### Issue: 500 Internal Server Error

**Solutions:**
1. Check PHP version (must be 8.2+)
2. Check file permissions
3. Check `.env` file exists and is readable
4. Check error logs in cPanel

### Issue: "No input file specified"

**Solution:**
Update `.htaccess`:
```apache
RewriteRule ^(.*)$ index.php?/$1 [L]
```

### Issue: "The stream or file could not be opened"

**Solution:**
```bash
chmod -R 777 storage
chmod -R 777 bootstrap/cache
```

### Issue: Database connection failed

**Solutions:**
1. Verify database credentials in `.env`
2. Check database exists in cPanel
3. Ensure user has ALL PRIVILEGES
4. Try `localhost` or `127.0.0.1` for DB_HOST

### Issue: "Class not found" errors

**Solution:**
```bash
composer dump-autoload --optimize
```

### Issue: Storage link not working

**Solution:**
Create symlink manually or use PHP script:
```php
<?php
$target = '/home/username/starmeet/storage/app/public';
$link = '/home/username/public_html/storage';
symlink($target, $link);
echo "Symlink created!";
```

---

## Useful cPanel Locations

| Feature | cPanel Location |
|---------|-----------------|
| PHP Version | Software > Select PHP Version |
| MySQL Databases | Databases > MySQL Databases |
| phpMyAdmin | Databases > phpMyAdmin |
| File Manager | Files > File Manager |
| FTP Accounts | Files > FTP Accounts |
| SSL/TLS | Security > SSL/TLS |
| Error Logs | Metrics > Errors |
| Subdomains | Domains > Subdomains |

---

## Quick Deployment Checklist

- [ ] PHP 8.2+ enabled in cPanel
- [ ] All required PHP extensions enabled
- [ ] MySQL database created
- [ ] Database user created with privileges
- [ ] Files uploaded to correct location
- [ ] `.env` file configured with correct DB credentials
- [ ] Application key generated
- [ ] `.htaccess` configured
- [ ] `index.php` points to correct Laravel path
- [ ] Storage permissions set (755)
- [ ] Migrations run successfully
- [ ] Seeders executed
- [ ] SSL certificate installed
- [ ] HTTPS forced (optional)

---

## Support

For issues specific to Namecheap hosting:
- Namecheap Support: https://www.namecheap.com/support/
- Knowledgebase: https://www.namecheap.com/support/knowledgebase/

For Laravel-specific issues:
- Laravel Documentation: https://laravel.com/docs/11.x
- StarMeet Documentation: README.md

---

**StarMeet** - Deployed on Namecheap Hosting with Laravel 11
