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

8.4 KiB

Installation

This guide covers a fresh manual deployment and the supplied local Docker development stack.

Requirements

  • Use PHP 8.4, the runtime used by the supplied Docker image (php:8.4-apache-bookworm).
  • Enable PHP's PDO MySQL driver (pdo_mysql).
  • MySQL 8.0 or a compatible MySQL server.
  • For Apache, enable mod_rewrite and mod_dir, allow .htaccess overrides for the project directory, and use the repository root as the document root. The included .htaccess uses FallbackResource /index.php for application routes.
  • The web-server user needs write access to the project uploads/ directory.

Configure the environment

From the project root, create the local environment and PHP configuration files required by the bootstrap:

cp .env.dist .env
cp config.dist.php config.php

The application loads .env from the project root, regardless of the web server's working directory. Keep both generated files local; .env and config.php are ignored by Git. Edit .env before serving the site:

Variable Purpose
STAGE Use production for a deployed site.
BASE_URL Public URL for the installation, for example https://example.com. For a subdirectory deployment, also configure the web server to route requests to this installation.
DATABASE_DRIVER Use mysql.
DATABASE_HOST Database server hostname; use mysql only when connecting to the Compose service.
DATABASE_DATABASE Database name.
DATABASE_USERNAME / DATABASE_PASSWORD Application database user credentials.
DATABASE_CHARSET The DB connection charset; utf8mb4 is recommended.
DATABASE_PREFIX Optional table prefix; leave empty unless required.
MYSQL_ROOT_PASSWORD Compose-only MySQL root password; set it for local Docker development and do not use it as the app's database password.
USERNAME Admin login name read directly by the existing Auth module.
PASSWORD_HASH Recommended admin password value; generate it as shown below.
PASSWORD Legacy plaintext fallback. Leave empty when using PASSWORD_HASH.
MAIL_HOST, MAIL_PORT, MAIL_ENCRYPTION SMTP server settings. Encryption may be tls, ssl, or none.
MAIL_USERNAME, MAIL_PASSWORD SMTP authentication credentials; leave empty when not required.
MAIL_FROM_ADDRESS, MAIL_FROM_NAME Sender identity used by the mailer.
MAIL_TIMEOUT SMTP connection timeout in seconds.

Generate a password hash with PHP, then paste the output into PASSWORD_HASH:

php -r 'echo password_hash("choose-a-unique-password", PASSWORD_DEFAULT), PHP_EOL;'

PASSWORD_HASH takes precedence over PASSWORD. The plaintext option remains only for backward compatibility; do not use it for a production deployment. Keep .env private, restrict its filesystem permissions, and ensure the web server cannot serve dotfiles. Never commit it.

Manual deployment

  1. Install PHP 8.4 with pdo_mysql, MySQL 8, and Apache with the modules and .htaccess settings listed above.

  2. Create an empty database and a dedicated application user. Grant that user the permissions needed to create and alter tables in this database; do not use the MySQL root account for the app.

    For a local MySQL server, an administrator can use SQL similar to the following, replacing the sample password and adapting the user host for your deployment:

    CREATE DATABASE plugi CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
    CREATE USER 'plugi'@'localhost' IDENTIFIED BY 'replace-with-a-unique-password';
    GRANT ALL PRIVILEGES ON plugi.* TO 'plugi'@'localhost';
    
  3. Place the project in the web root, copy .env.dist to .env and config.dist.php to config.php, and set the database name, user, password, host, public BASE_URL, admin login, and any SMTP settings. For a non-Docker deployment, DATABASE_HOST is usually localhost or the database host provided by your hosting provider—not mysql unless the host is actually named mysql.

  4. Make uploads/ writable by the PHP/web-server user. Use the narrowest owner/group permissions appropriate to your server; avoid making the whole project world-writable.

  5. Open the configured BASE_URL. Sign in with the USERNAME and password represented by PASSWORD_HASH at /admin/auth.

  6. On a fresh or outdated database, Plugi directs the administrator to the Website Manager database information/update flow. Use its database update action to create or update the schema, then reload the site.

The current schema definition is plugi-core/config/tables.php; the Website Manager update action applies the schema expected by the running application. Do not use plugi-core/config/create-tables.sql for a fresh setup: it is an old 2023 export and can be out of date. Back up any existing database before applying schema updates.

Local Docker development

The Compose stack is intended for local development only, not production. It uses PHP 8.4, MySQL 8.0, and the database hostname mysql; the web app and Adminer ports are bound to 127.0.0.1.

  1. Copy .env.dist to .env and config.dist.php to config.php.

  2. Set unique values for DATABASE_PASSWORD and MYSQL_ROOT_PASSWORD in .env. The same DATABASE_PASSWORD, DATABASE_DATABASE, and DATABASE_USERNAME values are used to initialize MySQL and connect the app. These values are development examples only.

  3. Keep DATABASE_HOST=mysql and set BASE_URL=http://localhost:63000 for the supplied ports. Set the admin login and password hash as described above.

  4. Start the stack from the project root:

    docker compose up --build -d
    
  5. Open http://localhost:63000, sign in at /admin/auth, and use the Website Manager database update flow when prompted. Adminer is available at http://localhost:63001; its database server name is mysql.

The MySQL data is stored in a named volume. docker compose down stops the stack without removing that volume; avoid docker compose down -v unless you intend to delete the database. Do not expose this development stack, its sample credentials, or Adminer as a production service.

Production and credential safety

  • Use HTTPS, production-strength unique credentials, and least-privilege database access. Keep .env out of version control and inaccessible over HTTP.
  • Configure the production web server to deny access to dotfiles and to the .env file explicitly; do not rely on a local Docker or Apache default for this protection.
  • The Compose stack and Adminer are development tools, not a production deployment recipe. Configure and harden production PHP, web server, database, backups, and monitoring separately.
  • SMTP credentials were previously present in tracked configuration. Treat them as exposed and rotate them with the mail provider; removing them from the current files does not remove them from Git history.

Troubleshooting

  • Missing .env: Copy .env.dist to .env in the project root. The loader requires this file at startup.
  • Missing config.php: Copy the tracked config.dist.php to config.php in the project root; the bootstrap requires the local config file.
  • Database connection refused: Check that MySQL is running and DATABASE_HOST is correct. Use mysql inside Compose and the actual host/localhost for a manual deployment.
  • Access denied or unknown database: Check the exact DATABASE_* names, database name, password, and grants. In Compose, the app and MySQL service must use the same database credentials.
  • Schema update repeats or fails: Confirm the database user can create/alter tables, back up existing data, and retry the Website Manager update flow. The application schema source is plugi-core/config/tables.php.
  • Routes return 404 or the homepage is served incorrectly: Confirm the project root is the document root, .htaccess overrides are allowed, and Apache's mod_rewrite and mod_dir modules are enabled.
  • A Docker port is already in use: Change the host-side port mapping in docker-compose.yml (for example, map 63002:80 instead of 63000:80) and update BASE_URL in .env to the matching local URL. Do the same for Adminer if port 63001 is occupied.
  • Uploads fail: Confirm the web-server user can write to uploads/ and that the configured storage path points to the project directory.
  • Mail does not send: Check the MAIL_* settings, sender address, SMTP port/encryption, and whether the provider requires authentication. The app will not have usable SMTP settings until configured.