# MetaApp cPanel Deployment Guide

## Quick Deployment Steps

### Step 1: Create MySQL Database in cPanel

1. Login to your cPanel
2. Go to **Databases** → **MySQL Database Wizard**
3. Create a new database (e.g., `metaapp_db`)
4. Create a database user with full permissions
5. Note down:
   - Database name
   - Database username
   - Database password

### Step 2: Import the SQL Database

1. In cPanel, go to **Databases** → **phpMyAdmin**
2. Select your newly created database
3. Click **Import** tab
4. Upload the `database-mysql.sql` file
5. Click **Go**

### Step 3: Upload Application Files

1. Logout from the current Laravel app (local development)
2. Delete the `.env` file (we'll create a new one)
3. Delete `database/database.sqlite` file
4. Delete `bootstrap/cache/*.php` files (keep .gitignore)
5. Delete `storage/logs/*.log` files
6. Delete debug files: `debug_*.php`, `sync_all_leads.php`, `export_sqlite.php`
7. Delete `meta` file (if present)
8. Delete `database.sql` (we have `database-mysql.sql`)
9. Delete `deploy.sh` and `CPANEL_DEPLOYMENT.md` (not needed on server)

### Step 4: Create Deployment ZIP

Create a zip file containing:
- All application files EXCEPT:
  - `.git` folder
  - `node_modules` folder
  - `.env` file
  - SQLite database file
  - Any debug/test files
  - `*.log` files in storage/logs

**Recommended exclusions:**
```
.git
node_modules
.env
*.log
storage/logs/*.log
database/database.sqlite
debug_*.php
sync_all_leads.php
export_sqlite.php
database.sql
meta
deploy.sh
CPANEL_DEPLOYMENT.md
composer.lock (optional - for fresh install)
package-lock.json
```

### Step 5: Upload and Extract

1. Login to cPanel → **Files** → **File Manager**
2. Navigate to `public_html` (or your subdomain folder)
3. Upload the deployment ZIP file
4. Right-click → **Extract**
5. Move extracted files to the correct location

### Step 6: Configure .env File

Create a new `.env` file with these settings:

```env
APP_NAME="Maven Group"
APP_ENV=production
APP_KEY=base64:YOUR_APP_KEY_HERE
APP_DEBUG=false
APP_URL=https://your-domain.com

DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=your_database_name
DB_USERNAME=your_database_user
DB_PASSWORD=your_database_password

BROADCAST_DRIVER=log
CACHE_DRIVER=file
FILESYSTEM_DISK=local
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120

MAIL_MAILER=smtp
MAIL_HOST=smtp.your-provider.com
MAIL_PORT=587
MAIL_USERNAME=your-email@domain.com
MAIL_PASSWORD=your-email-password
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=noreply@your-domain.com
MAIL_FROM_NAME="Maven Group"

META_ACCESS_TOKEN=your_meta_access_token_here
META_AD_ACCOUNT_ID=act_123456789
META_APP_ID=your_app_id
META_APP_SECRET=your_app_secret
META_DEMO_MODE=false

NOTIFICATION_EMAILS="kavitha@mavengroup.in,koushik@mavengroup.in"
```

### Step 7: Generate Application Key

If you didn't provide an APP_KEY in .env, generate one:

```bash
php artisan key:generate
```

### Step 8: Set File Permissions

Set these permissions via cPanel File Manager or SSH:

```bash
chmod -R 755 storage
chmod -R 755 bootstrap/cache
chmod 644 .env
chmod 644 storage/logs/.gitkeep
```

### Step 9: Configure Cron Job (Optional)

For automatic Meta data sync, add a cron job via cPanel:

1. Go to **Advanced** → **Cron Jobs**
2. Add a new cron job:

```
* * * * * cd /home/username/public_html && php artisan schedule:run >> /dev/null 2>&1
```

Replace `/home/username/public_html` with your actual path.

### Step 10: Test the Application

Visit your domain to verify the application is working.

---

## Default Login Credentials

- **Email:** admin@gmail.com
- **Password:** (use password reset or set manually in database)

To set a new password directly in MySQL:

```sql
UPDATE users SET password = '$2y$10$YOUR_HASHED_PASSWORD' WHERE email = 'admin@gmail.com';
```

Generate a hash using:
```bash
php artisan tinker
>>> Hash::make('your-new-password')
```

---

## Troubleshooting

### 500 Internal Server Error

1. Check `storage/logs/laravel.log` for errors
2. Verify `.env` file exists and has correct database credentials
3. Ensure file permissions are correct (755 for directories, 644 for files)
4. Check PHP version (requires PHP 8.1+)

### Database Connection Error

1. Verify database name, username, and password in `.env`
2. Ensure the database user has permissions for the database
3. Check if MySQL host is `localhost` (usually correct for shared hosting)

### Blank White Page

1. Enable debug mode temporarily: `APP_DEBUG=true`
2. Check error logs in `storage/logs/`

### Permission Denied Errors

```bash
chmod -R 755 storage bootstrap/cache
chown -R your_username:your_username public_html
```

---

## cPanel Requirements

- **PHP Version:** 8.1 or higher
- **MySQL Version:** 5.7+ or MariaDB 10.3+
- **Extensions Required:**
  - BCMath PHP Extension
  - Ctype PHP Extension
  - Fileinfo PHP Extension
  - JSON PHP Extension
  - Mbstring PHP Extension
  - OpenSSL PHP Extension
  - PDO PHP Extension
  - PDO SQLite PHP Extension (if using SQLite locally)
  - Tokenizer PHP Extension
  - XML PHP Extension
  - GD PHP Extension
  - Intl PHP Extension

---

## Files Created for Deployment

1. **database-mysql.sql** - MySQL-compatible database file ready for import
2. **.env.production** - Template for production .env file
3. **CPANEL_DEPLOYMENT.md** - This deployment guide

---

## Support

For issues, check:
1. Laravel logs: `storage/logs/laravel.log`
2. Apache error logs in cPanel
3. phpMyAdmin for database issues
