# CoreERP — Production Environment Template

> **Important:** This file contains **safe placeholder values only**.  
> Never copy real credentials into this file. Fill in the actual `.env` file on the server directly.

---

## How to use

1. SSH into the production server.
2. Navigate to the project root.
3. Copy the example file: `cp .env.example .env`
4. Edit `.env` using the values described below: `nano .env`
5. Run `php artisan config:cache` after editing.

---

## Application Settings

```env
APP_NAME="CoreERP"
APP_ENV=production
APP_KEY=                          # Auto-generated by: php artisan key:generate
APP_DEBUG=false                   # MUST be false in production
APP_URL=https://yourdomain.com    # Full HTTPS URL, no trailing slash

APP_LOCALE=en
APP_FALLBACK_LOCALE=en
```

> **APP_DEBUG=false** is mandatory in production. Setting it to `true` exposes sensitive stack traces, environment values, and database credentials to any browser that triggers an error.

---

## Database Settings

Switch from the default SQLite to MySQL/MariaDB for production:

```env
DB_CONNECTION=mysql
DB_HOST=127.0.0.1               # Or the IP/hostname of your DB server
DB_PORT=3306
DB_DATABASE=your_database_name
DB_USERNAME=your_db_username
DB_PASSWORD=your_strong_password

# Optional: force UTF-8 (recommended)
DB_CHARSET=utf8mb4
DB_COLLATION=utf8mb4_unicode_ci
```

---

## Session Settings

```env
SESSION_DRIVER=database          # Recommended: keeps sessions in DB (survives server restart)
SESSION_LIFETIME=120             # Minutes of inactivity before session expires
SESSION_SECURE_COOKIE=true       # Set to true when running on HTTPS
SESSION_ENCRYPT=false            # Set to true for extra security (requires APP_KEY)
```

---

## Cache Settings

```env
CACHE_STORE=database             # Recommended default (uses DB cache table)

# Alternative for high-traffic sites: use Redis
# CACHE_STORE=redis
# REDIS_HOST=127.0.0.1
# REDIS_PASSWORD=your_redis_password
# REDIS_PORT=6379
```

---

## Queue Settings

```env
QUEUE_CONNECTION=database        # Recommended default (uses DB jobs table)

# For production with high volume jobs, consider Redis:
# QUEUE_CONNECTION=redis
```

> If using database queues, run the queue worker as a supervised process:
> ```bash
> php artisan queue:work --daemon --sleep=3 --tries=3
> ```

---

## Mail Settings

```env
MAIL_MAILER=smtp
MAIL_SCHEME=tls
MAIL_HOST=smtp.yourprovider.com
MAIL_PORT=587
MAIL_USERNAME=your_email@yourdomain.com
MAIL_PASSWORD=your_mail_password
MAIL_FROM_ADDRESS="noreply@yourdomain.com"
MAIL_FROM_NAME="CoreERP"
```

> Common providers: Gmail (smtp.gmail.com:587), Brevo, Mailgun, Amazon SES.  
> During testing, set `MAIL_MAILER=log` to write emails to `storage/logs/laravel.log` instead of sending them.

---

## Logging

```env
LOG_CHANNEL=daily                # Recommended for production (rotates daily)
LOG_LEVEL=warning                # Only log warnings and above; reduce log noise
```

---

## Filesystem / Storage

```env
FILESYSTEM_DISK=local            # Local disk (files in storage/app)

# For cloud storage (optional future upgrade):
# FILESYSTEM_DISK=s3
# AWS_ACCESS_KEY_ID=your_key_id
# AWS_SECRET_ACCESS_KEY=your_secret_key
# AWS_DEFAULT_REGION=us-east-1
# AWS_BUCKET=your_bucket_name
```

---

## Settings to leave empty or as-is

```env
BROADCAST_CONNECTION=log
MEMCACHED_HOST=127.0.0.1        # Only needed if CACHE_STORE=memcached
AWS_ACCESS_KEY_ID=               # Only needed for S3/SES
AWS_SECRET_ACCESS_KEY=
AWS_BUCKET=
```

---

## Quick security checklist before going live

- [ ] `APP_DEBUG=false`
- [ ] `APP_ENV=production`
- [ ] `APP_URL` uses `https://`
- [ ] `SESSION_SECURE_COOKIE=true`
- [ ] Strong `DB_PASSWORD` (12+ characters, mixed case + symbols)
- [ ] `php artisan key:generate` run once (on first deployment only)
- [ ] `.env` file is not readable by the web server (confirm: `curl https://yourdomain.com/.env` should return 403 or redirect)
- [ ] `.env` not committed to git (check `.gitignore` contains `.env`)

---

*Prepared as part of Phase 15A-15C — Backup & Deployment Preparation.*
