# LaunchMint – Production & cPanel Deployment

## 1. Local installation

```bash
git clone <your-repo> launchmint
cd launchmint
composer install --no-dev --optimize-autoloader
cp .env.example .env
php artisan key:generate
```

Edit `.env`:

```env
APP_NAME=LaunchMint
APP_ENV=production
APP_DEBUG=false
APP_URL=https://yourdomain.com

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=launchmint
DB_USERNAME=...
DB_PASSWORD=...

QUEUE_CONNECTION=database   # or redis
CACHE_STORE=redis           # recommended
SESSION_DRIVER=redis

# Blockchain (server-side only – never expose in JS)
EVM_RPC_URL=https://...
EVM_FACTORY_ADDRESS=0x...
BASE_RPC_URL=
BSC_RPC_URL=
EVM_EXPLORER_API_KEY=
```

```bash
php artisan migrate --force
php artisan db:seed --force
php artisan storage:link
npm ci && npm run build
php artisan config:cache
php artisan route:cache
php artisan view:cache
```

---

## 2. MySQL setup

1. Create database + user in cPanel → MySQL Databases (or phpMyAdmin).
2. Grant ALL on the database to the user.
3. Put credentials in `.env` as above.
4. Run migrations from SSH or a one-time cron/PHP script.

---

## 3. cPanel document root

**Recommended layout**

```
/home/USERNAME/
  launchmint/          ← application root (outside public_html)
    app/
    bootstrap/
    config/
    database/
    public/            ← web-accessible files
    ...
  public_html/         ← or subdomain folder
```

**Option A – Subdomain / addon domain**

1. Create subdomain e.g. `app.yourdomain.com`.
2. Set document root to `/home/USERNAME/launchmint/public`.

**Option B – Main domain with public_html**

1. Upload the full project to e.g. `/home/USERNAME/launchmint`.
2. In `public_html`, either:
   - Delete default files and create a symlink:
     ```bash
     ln -s /home/USERNAME/launchmint/public/* /home/USERNAME/public_html/
     # or point the domain document root to launchmint/public in cPanel
     ```
   - Or place an `.htaccess` in `public_html` that rewrites to the real `public` folder.

**Critical:** Only the contents of `public/` must be web-accessible. Never expose `.env`, `vendor/`, `storage/logs`, etc.

---

## 4. PHP version

cPanel → Select PHP Version → **8.2 or 8.3**.

Enable extensions:

- `pdo_mysql`, `mbstring`, `openssl`, `tokenizer`, `xml`, `ctype`, `json`, `bcmath`, `fileinfo`, `gd` or `imagick`, `redis` (if available), `curl`

---

## 5. Composer on cPanel

```bash
cd ~/launchmint
php -d allow_url_fopen=1 /usr/local/bin/composer install --no-dev --optimize-autoloader
```

If Composer is not in PATH, download it:

```bash
curl -sS https://getcomposer.org/installer | php
php composer.phar install --no-dev --optimize-autoloader
```

---

## 6. Storage & permissions

```bash
php artisan storage:link
chmod -R 775 storage bootstrap/cache
chown -R USERNAME:USERNAME storage bootstrap/cache
```

Ensure `storage/app/public` is writable for token logos.

---

## 7. SSL

cPanel → SSL/TLS Status → AutoSSL, or install a Let’s Encrypt certificate.  
Force HTTPS in `.env` (`APP_URL=https://...`) and optionally in `.htaccess`:

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

---

## 8. Cron (Laravel Scheduler)

cPanel → Cron Jobs → Add:

```
* * * * * cd /home/USERNAME/launchmint && php artisan schedule:run >> /dev/null 2>&1
```

This runs:

- `UpdateTokenMetricsJob` every 5 minutes  
- `CleanExpiredWalletNoncesJob` hourly  

---

## 9. Queue worker

Confirmation of blockchain transactions **requires** a queue worker.

**Option A – long-running process (VPS / SSH with screen/tmux)**

```bash
php artisan queue:work --sleep=3 --tries=3 --max-time=3600
```

Use Supervisor if available.

**Option B – cPanel cron every minute (simpler, less ideal)**

```
* * * * * cd /home/USERNAME/launchmint && php artisan queue:work --stop-when-empty --max-time=50 >> /dev/null 2>&1
```

Set in `.env`:

```env
QUEUE_CONNECTION=database
```

Then:

```bash
php artisan queue:table
php artisan migrate
```

---

## 10. Environment variables (secrets)

- Put **all** RPC URLs, factory addresses, mail passwords, and Redis passwords only in `.env`.
- Never commit `.env`.
- Never inject RPC keys into Blade/JS.
- After changing `.env` in production:

```bash
php artisan config:cache
```

---

## 11. Production optimization checklist

- [ ] `APP_DEBUG=false`
- [ ] `APP_ENV=production`
- [ ] `config:cache`, `route:cache`, `view:cache`
- [ ] `composer install --no-dev`
- [ ] `npm run build` (assets in `public/build`)
- [ ] HTTPS only
- [ ] Queue worker running
- [ ] Cron for scheduler
- [ ] File upload limits (PHP `upload_max_filesize` ≥ 4M)
- [ ] Rate limiting enabled (already in `routes/api.php`)
- [ ] Admin user created (`is_admin = 1`)

---

## 12. First admin user

```bash
php artisan tinker
>>> $u = \App\Models\User::where('email', 'you@example.com')->first();
>>> $u->is_admin = true; $u->save();
```

Or via SQL:

```sql
UPDATE users SET is_admin = 1 WHERE email = 'you@example.com';
```

Visit `https://yourdomain.com/admin`.

---

## 13. Blockchain configuration reminder

Until `EVM_FACTORY_ADDRESS` (and a working RPC) are set, token creation still works but tokens remain **pending**.  
Deployment transactions are only marked **launched** after `ProcessBlockchainTransactionJob` sees an on-chain confirmation.

Do **not** invent or hard-code private keys. Prefer user-signed factory transactions or a carefully audited deployer key held only on the server.

---

## 14. Troubleshooting

| Issue | Check |
|-------|--------|
| 500 errors | `storage/logs/laravel.log`, PHP version, permissions |
| Assets 404 | `npm run build`, `APP_URL`, mix/vite manifest |
| Queue not processing | Worker running? `QUEUE_CONNECTION`? `failed_jobs` table |
| Wallet verify fails | Keccak/elliptic packages for full recovery, or test with known message |
| Uploads fail | `storage` permissions, `upload_max_filesize` |

---

## Support

This codebase is a full scaffold. Wire a real token factory contract and a price/liquidity indexer for production trading and charts.
EOF
echo "DEPLOYMENT.md written"
