Files
plugi-docs/Configuration.md
2026-11-27 17:23:32 +01:00

219 lines
8.4 KiB
Markdown

# Configuration
Plugi is configured through two files:
- **`.env`** — Environment-specific database, stage, admin-login, and mail settings.
- **`config.php`** — PHP array that controls framework behavior, modules, themes, and extensions; copy it from `config.dist.php` for a fresh checkout.
## The `.env` File
The `.env` file is loaded from the project root by `EnvLoader` at boot time. Start with `.env.dist` and use the exact variable names below:
```ini
STAGE=production
BASE_URL=https://example.com
DATABASE_DRIVER=mysql
DATABASE_HOST=localhost
DATABASE_DATABASE=plugi
DATABASE_USERNAME=plugi
DATABASE_PASSWORD=replace-with-a-unique-password
DATABASE_CHARSET=utf8mb4
DATABASE_PREFIX=
USERNAME=admin
PASSWORD=
PASSWORD_HASH=
MAIL_HOST=
MAIL_PORT=587
MAIL_ENCRYPTION=tls
MAIL_USERNAME=
MAIL_PASSWORD=
MAIL_FROM_ADDRESS=
MAIL_FROM_NAME=
MAIL_TIMEOUT=10
```
| Variables | Purpose |
|-----------|---------|
| `STAGE`, `BASE_URL` | Select the application stage and public URL. Set the stage to `production` for a deployed site. |
| `DATABASE_DRIVER`, `DATABASE_HOST`, `DATABASE_DATABASE`, `DATABASE_USERNAME`, `DATABASE_PASSWORD`, `DATABASE_CHARSET`, `DATABASE_PREFIX` | Database connection settings read by `DB`. Use `DATABASE_HOST=mysql` only when connecting to the supplied Compose service. |
| `USERNAME`, `PASSWORD_HASH`, `PASSWORD` | Admin login read by the Auth module. Prefer `PASSWORD_HASH`; `PASSWORD` is a legacy plaintext fallback. |
| `MAIL_HOST`, `MAIL_PORT`, `MAIL_ENCRYPTION`, `MAIL_USERNAME`, `MAIL_PASSWORD`, `MAIL_FROM_ADDRESS`, `MAIL_FROM_NAME`, `MAIL_TIMEOUT` | SMTP settings mapped from the environment into the existing mail configuration by `config.php` / `config.dist.php`. |
`MYSQL_ROOT_PASSWORD` is only used by the local Compose database container; it is not the application's database password. Keep `.env` private and never commit it.
Setting `STAGE=production` disables PHP error display in `index.php`.
## The `config.php` File
Copy `config.dist.php` to `config.php` and adjust the settings. The configuration is a PHP array with the following sections:
### General Settings
```php
'general' => [
'language' => 'en',
'assets_url' => '/plugi-core/dist',
'uploads_url' => '/uploads'
],
```
| Key | Description |
|----------------|--------------------------------------------------|
| `language` | Default language code (e.g., `en`, `de`, `fr`). Theme and extension translations are loaded for this language. |
| `assets_url` | Public URL path to the Plugi core assets (JS, CSS, images). |
| `uploads_url` | Public URL path to the uploads directory. |
### Storage Settings
```php
'storage' => [
'use_database' => true,
'uploads_folder' => __DIR__ . '/uploads'
],
```
| Key | Description |
|--------------------|----------------------------------------------------------|
| `use_database` | Set to `true` to use MySQL for storing pages, settings, and uploads metadata. |
| `uploads_folder` | Absolute filesystem path where uploaded files are stored. |
### Auth Settings
```php
'auth' => [
'use_login' => true,
'class' => Plugi\Modules\Auth\Auth::class,
'url' => '/admin/auth',
],
```
| Key | Description |
|---------------|-----------------------------------------------------------------------------|
| `use_login` | Enable or disable the built-in authentication module. |
| `class` | Fully qualified class name implementing `AuthContract`. |
| `url` | URL prefix for auth endpoints (login/logout). |
The default `Auth` class reads `USERNAME` and either `PASSWORD_HASH` or the legacy `PASSWORD` value from `.env`; credentials are not configured in the PHP `auth` array. Use a password hash for deployments and leave `PASSWORD` empty.
### Website Manager Settings
```php
'website_manager' => [
'use_website_manager' => true,
'class' => Plugi\Modules\WebsiteManager\WebsiteManager::class,
'url' => '/admin'
],
```
| Key | Description |
|---------------------------|-----------------------------------------------------------------------|
| `use_website_manager` | Enable or disable the admin dashboard. |
| `class` | Class implementing `WebsiteManagerContract`. |
| `url` | URL prefix for the admin panel. |
### Page Builder Settings
```php
'pagebuilder' => [
'class' => Plugi\Modules\GrapesJS\PageBuilder::class,
'url' => '/admin/pagebuilder',
'actions' => [
'back' => '/admin'
]
],
```
| Key | Description |
|-------------|---------------------------------------------------------------|
| `class` | Class implementing `PageBuilderContract` (GrapesJS-based by default). |
| `url` | URL prefix for the page builder. |
| `actions` | Named action URLs, e.g., `back` returns to the admin panel. |
### Page Settings
```php
'page' => [
'class' => Plugi\Page::class,
'table' => 'pages',
'translation' => [
'class' => Plugi\PageTranslation::class,
'table' => 'page_translations',
'foreign_key' => 'page_id',
]
],
```
| Key | Description |
|-----------------------|---------------------------------------------------------------|
| `class` | Class implementing `PageContract`. |
| `table` | Database table name for pages. |
| `translation.class` | Class implementing `PageTranslationContract`. |
| `translation.table` | Database table name for page translations (multilingual support). |
| `translation.foreign_key` | Foreign key column linking translations to pages. |
### Cache Settings
```php
'cache' => [
'enabled' => false,
'folder' => __DIR__ . '/cache',
'class' => Plugi\Cache::class
],
```
| Key | Description |
|-------------|-----------------------------------------------------------------------------|
| `enabled` | Enable page caching. Cached pages skip block parsing on subsequent requests. |
| `folder` | Filesystem path for cache files. |
| `class` | Class implementing `CacheContract`. |
A page is cached unless it contains a block with caching disabled. The cache is automatically cleared when a page is saved in the page builder. You can also force a cache refresh by appending `?refresh_cache` to the URL.
### Theme Settings
```php
'theme' => [
'class' => Plugi\Theme::class,
'folder' => __DIR__ . '/themes',
'folder_url' => '/themes',
'active_theme' => 'theme-one'
],
```
| Key | Description |
|------------------|---------------------------------------------------------------|
| `class` | Class implementing `ThemeContract`. |
| `folder` | Filesystem path to the themes directory. |
| `folder_url` | Public URL path to the themes directory. |
| `active_theme` | Slug of the active theme (matches a folder name in `themes/`). |
### Router Settings
```php
'router' => [
'class' => Plugi\Modules\Router\DatabasePageRouter::class
],
```
| Key | Description |
|-----------|---------------------------------------------------------------|
| `class` | Class implementing `RouterContract` that resolves URLs to pages. |
### Class Replacements
```php
'class_replacements' => [
// Plugi\UploadedFile::class => Alternative\UploadedFile::class
],
```
Map a core class namespace to an alternative implementation. This allows overriding specific classes while extending the originals. Example:
```php
'class_replacements' => [
Plugi\UploadedFile::class => My\App\CustomUploadedFile::class,
],
```
> **Important:** When overriding a class, always extend the original class.