feat: add Docker setup exposing app on port 7876

- Dockerfile: php:apache base, installs PHP extensions + Composer,
  configures Apache to listen on port 7876, bundles app code,
  runs composer install at build time
- docker-compose.yml: web service (port 7876) + MariaDB LTS with
  healthcheck; writable volume for DB persistence
- docker/entrypoint.sh: generates .env from environment variables
  at container start, fixes runtime permissions
- docker/php.ini: tuned PHP limits (512M memory, 32M upload)
- .dockerignore: excludes .git, vendor, logs, cache, old docker dir
- .env.example: template for required environment variables

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-29 08:52:57 +02:00
parent 6145e45059
commit a0328d69f6
6 changed files with 187 additions and 0 deletions

44
docker/entrypoint.sh Normal file
View File

@@ -0,0 +1,44 @@
#!/usr/bin/env bash
set -euo pipefail
ENV_FILE="/var/www/html/.env"
upsert_kv() {
local key="$1" val="$2"
if grep -qE "^${key}=" "$ENV_FILE" 2>/dev/null; then
sed -i "s#^${key}=.*#${key}=${val}#" "$ENV_FILE"
else
printf "%s=%s\n" "$key" "$val" >> "$ENV_FILE"
fi
}
# Bootstrap .env from template if not present
if [ ! -f "$ENV_FILE" ]; then
if [ -f /var/www/html/env.example.txt ]; then
cp /var/www/html/env.example.txt "$ENV_FILE"
else
touch "$ENV_FILE"
fi
fi
# Inject database and app config from environment variables
upsert_kv "DB_HOST" "${DB_HOST:-db}"
upsert_kv "DB_PORT" "${DB_PORT:-3306}"
upsert_kv "DB_DATABASE" "${DB_DATABASE:-domain_monitor}"
upsert_kv "DB_USERNAME" "${DB_USERNAME:-domain_monitor}"
upsert_kv "DB_PASSWORD" "${DB_PASSWORD:-}"
upsert_kv "APP_ENV" "${APP_ENV:-production}"
[ -n "${APP_ENCRYPTION_KEY:-}" ] && upsert_kv "APP_ENCRYPTION_KEY" "$APP_ENCRYPTION_KEY"
[ -n "${SESSION_LIFETIME:-}" ] && upsert_kv "SESSION_LIFETIME" "$SESSION_LIFETIME"
# Ownership & permissions on runtime-writable paths
chown www-data:www-data "$ENV_FILE"
chmod 660 "$ENV_FILE"
for d in logs cache public/assets/uploads; do
dir="/var/www/html/$d"
[ -d "$dir" ] && chown -R www-data:www-data "$dir" && chmod -R 775 "$dir"
done
exec "$@"

19
docker/php.ini Normal file
View File

@@ -0,0 +1,19 @@
; ---- PHP limits ----
max_execution_time = 0
max_input_time = -1
max_input_vars = 3000
memory_limit = 512M
post_max_size = 32M
upload_max_filesize = 16M
default_socket_timeout = 120
; Recommended defaults
date.timezone = UTC
display_errors = Off
error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT
; Opcache
opcache.enable=1
opcache.enable_cli=1
opcache.validate_timestamps=1
opcache.revalidate_freq=2