Salta ai contenuti
PHP Ecosystem
Explore

Configuration reference

Questi contenuti non sono ancora disponibili nella tua lingua.

Every setting is an environment variable read when the container starts. The default is the value set by the image or, when the image does not set the variable, the value the entrypoint falls back to.

The entrypoint runs these steps in order and then starts the command.

  1. Prints a banner with the variant, PHP version, user, YII_ENV and YII_DEBUG.
  2. Creates the runtime state in /run/yii2 and the application directories, configures Apache, fixes permissions (root).
  3. Waits for the configured services, when enabled.
  4. Runs composer install, unless skipped.
  5. Runs the Yii migrations, when enabled.
  6. Starts supervisord (Apache and PHP-FPM) or, when a command is given, runs that command instead.

Step 2 creates runtime, web/assets and web/uploads under /var/www/app and writes the Apache ports and defines for HTTPS, the health endpoint and the PHP-FPM status. As root it also creates the www-data home directories and assigns runtime and web/assets to www-data, skipping any path that is or passes through a symbolic link; as any other user it creates what it can and logs the remedy for what it cannot write. Apache configuration lives under /etc/apache2 and is static: the entrypoint only selects which sections apply through Apache defines, it never rewrites configuration files.

The stack runs as the container user: www-data by default, any UID:GID with --user (no passwd entry needed), or root with --user root, where Apache and PHP-FPM drop their workers to www-data. supervisord cannot assign programs to another user unless it is root, so custom programs in /etc/supervisor/conf.d only keep user= lines in root mode.

PathContent
/run/yii2/apacheruntime.env (defines, ports, certificate paths), pid file, locks, SSL caches
/run/yii2/phpPHP-FPM socket
/run/yii2/supervisorsupervisord pid file and control socket
/run/yii2/sslGenerated self-signed certificate and key
/run/yii2/sessionsPHP sessions (PHP_SESSION_PATH)
/run/yii2/tmpPHP upload and temporary files

The entrypoint creates these directories at every start for the running user; in root mode they belong to root, except sessions and tmp, which belong to www-data. /etc/apache2/envvars sources runtime.env only when the calling user owns it, so run docker exec as the container user (the default) to get the same Apache configuration. In root mode nothing that root sources, executes or loads as configuration is writable by www-data; in the non-root modes no process can become root.

A read-only root filesystem works with tmpfs mounts for the runtime state and the temporary directory, plus writable application directories when the application is part of the image:

Terminal window
docker run -d --read-only --tmpfs /run/yii2:mode=1777 --tmpfs /tmp:mode=1777 \
--tmpfs /var/www/app/runtime:uid=33,gid=33 --tmpfs /var/www/app/web/assets:uid=33,gid=33 \
-p 127.0.0.1:8080:80 -p 127.0.0.1:8443:443 my-app

Ports 80 and 443 can be bound by a non-root user under docker run (Docker sets net.ipv4.ip_unprivileged_port_start=0). Kubernetes and --network host usually keep the 1024 limit: set APACHE_HTTP_PORT=8080 and APACHE_HTTPS_PORT=8443 and map or expose those ports. The entrypoint stops with this remedy when a configured port is privileged for the running user.

VariableDefaultDescription
DEBUG_ENTRYPOINTfalsetrue prints debug messages from the entrypoint.
CUSTOM_DIRECTORIESemptyComma-separated list of extra directories to create and assign to www-data at startup (root only).
BUILD_TYPEvariantSet by the image to prod, dev or full. Selects the Composer defaults below; do not override it.
SERVICE_TYPEapache-fpmSet by the image. Apache is configured only for apache-fpm; do not override it.
YII_ENVemptyShown in the banner and the health response. test enables the service wait and skips migrations.
YII_DEBUGemptyShown in the banner.

The entrypoint opens a TCP connection to every configured host until it succeeds or the timeout expires.

VariableDefaultDescription
WAIT_FOR_SERVICESfalsetrue enables the wait. It is also enabled when YII_ENV=test.
SKIP_DB_WAITfalsetrue disables the wait in every case.
SERVICE_WAIT_TIMEOUT30Seconds to wait for each service.
FAIL_ON_SERVICE_TIMEOUTfalsetrue exits with status 1 when a service is not reachable; false logs and continues.

Only services whose host variable is set are checked.

Host variablePort variableDefault port
DB_MYSQL_HOSTDB_MYSQL_PORT3306
DB_PGSQL_HOSTDB_PGSQL_PORT5432
DB_REDIS_HOSTDB_REDIS_PORT6379
DB_MONGODB_HOSTDB_MONGODB_PORT27017
DB_MSSQL_HOSTDB_MSSQL_PORT1433
DB_ORACLE_HOSTDB_ORACLE_PORT1521

composer install runs in /var/www/app as www-data (or as the current user when not root), only when composer.json exists, with --no-interaction --no-progress --optimize-autoloader --prefer-dist. --no-dev is added when YII_ENV=prod or BUILD_TYPE=prod.

VariableDefaultDescription
SKIP_COMPOSER_INSTALLtrue for prod, false otherwisetrue skips the install. An explicit value always wins over the variant default.
FORCE_COMPOSER_INSTALLfalsetrue installs even when vendor/ already exists.
FIX_PERMStrueAs root, true runs chown -R www-data:www-data and chmod -R g+rwX on /var/www/app before the install.
FAIL_ON_COMPOSER_ERRORfalsetrue exits with status 1 when the install fails; false logs and continues.
COMPOSER_HOME/var/www/.composerSet by the image.

FIX_PERMS acts only when the install runs (not skipped, composer.json present, no vendor/ unless FORCE_COMPOSER_INSTALL=true), as in v1: it gives www-data write access for Composer and leaves the application alone otherwise, so the prod default never makes the code writable by the web server. In root mode the entrypoint always hands runtime/ and web/assets/ to www-data when they exist.

VariableDefaultDescription
YII_RUN_MIGRATIONSfalsetrue runs php yii migrate --interactive=0. Skipped without yii or in test.
FAIL_ON_MIGRATION_ERRORtruetrue exits with status 1 when a migration fails; false logs and continues.

Migrations run as the application user: the selected non-root UID, or www-data in root mode.

VariableDefaultDescription
APACHE_HTTP_PORT80HTTP port; the healthcheck uses it.
APACHE_HTTPS_PORT443HTTPS listener and virtual host port.
APACHE_SSL_ENABLEDtruetrue serves HTTPS with HTTP/2 on APACHE_HTTPS_PORT. false serves HTTP only and does not open APACHE_HTTPS_PORT.
APACHE_SSL_REDIRECTfalsetrue redirects HTTP to HTTPS with status 301 (see below).
SSL_AUTO_GENERATEtruetrue generates a self-signed certificate (RSA 2048, valid 365 days) when the files are missing.
SSL_DIR/etc/apache2/sslSearched for mounted certificates and openssl.conf.
SSL_CERT_FILE${SSL_DIR}/cert.pemCertificate file.
SSL_KEY_FILE${SSL_DIR}/key.pemPrivate key file.
SSL_CHAIN_FILEemptyOptional chain file. A path that does not exist is ignored with a warning.
APACHE_DISABLE_OCSP_STAPLINGfalsetrue disables OCSP stapling.
APACHE_DOCUMENT_ROOT/var/www/app/webDocument root.
APACHE_ACCESS_LOG/proc/self/fd/1Access log destination (JSON lines).
APACHE_ERROR_LOG_FILE/proc/self/fd/2Error log destination.
APACHE_ARGUMENTSemptyExtra arguments for apache2ctl; the entrypoint appends its own -D defines.

APACHE_DOCUMENT_ROOT selects the application’s public directory; it does not relocate the application root /var/www/app used by startup, Composer or migrations. The sensitive-directory rule covers source directories at that application root and one level below it, excluding the configured public subtree. If you serve application files from another root or add aliases, configure access restrictions for those paths explicitly.

The default configuration preserves application cookie attributes, error response bodies and dynamic JSON cache policy. Static MIME types retain their explicit cache lifetimes. The default CSP upgrades insecure resources on HTTPS responses only; an application-supplied CSP takes precedence.

JSON access logs keep their field names and numeric types. Valid UTF-8 is preserved; bytes outside valid UTF-8 sequences are represented as \u00HH, one code point per original byte. Literal backslashes remain literal. Encoding runs inside Apache without a logging subprocess, using the selected access-log destination and Apache’s normal write-error reporting. The default unbuffered writer serializes whole records across workers.

When HTTPS is enabled but no certificate is usable (files missing and SSL_AUTO_GENERATE=false, or generation failed), the container starts HTTP only and logs a warning.

With APACHE_SSL_REDIRECT=true, requests for localhost are redirected to https://localhost:8443, matching a 8443:443 port mapping; requests for any other host name are redirected to port 443. With another APACHE_HTTPS_PORT, every host is redirected to that port. The internal /__health endpoint is never redirected.

OCSP stapling is enabled only for certificates you provide: when SSL_AUTO_GENERATE is not true and APACHE_DISABLE_OCSP_STAPLING is not true.

VariableDefault
APACHE_ASYNC_REQUEST_WORKER_FACTOR2
APACHE_GRACEFUL_SHUTDOWN_TIMEOUT10
APACHE_LISTEN_BACKLOG511
APACHE_MAX_CONNECTIONS_PER_CHILD5000
APACHE_MAX_REQUEST_WORKERS800
APACHE_MAX_SPARE_THREADS100
APACHE_MIN_SPARE_THREADS25
APACHE_SERVER_LIMIT32
APACHE_START_SERVERS4
APACHE_THREAD_LIMIT64
APACHE_THREADS_PER_CHILD25

Each variable maps to the MPM directive of the same name.

The health script is part of the image and runs through Apache and PHP-FPM. Application rewrite rules and .htaccess files do not apply to it, nothing is written to the application directory, and served health requests are not written to the access log.

VariableDefaultDescription
ENABLE_HEALTH_ENDPOINTtruefalse disables the public endpoint; the path then reaches the application.
HEALTHCHECK_PATH/healthPublic endpoint path, answered with and without a trailing slash.
SERVICE_NAMEyii2-appservice field of the response.
APP_VERSIONunknownversion field of the response.

Non-empty endpoint values are literal absolute URL paths. Whitespace, quotes, backslashes, queries and fragments are rejected at startup. FPM status and ping paths must also use the characters accepted by PHP-FPM. An empty HEALTHCHECK_PATH uses /health.

The response is a JSON document with the fields status (healthy), timestamp, service, version, environment (YII_ENV), php_version and checks (whether pdo, intl and opcache are loaded).

The path /__health is reserved. It is always enabled, answers loopback requests only and backs the healthcheck command that the Docker HEALTHCHECK runs, so the container turns unhealthy when Apache or PHP-FPM stops answering. It does not depend on ENABLE_HEALTH_ENDPOINT or APACHE_SSL_REDIRECT.

VariableDefaultDescription
ENABLE_FPM_STATUSfalsetrue serves the PHP-FPM status and ping pages to loopback only.
PHP_FPM_STATUS_PATH/fpm-statusStatus page path. Append ?full for the per-process status.
PHP_FPM_PING_PATH/fpm-pingPing path; answers pong.

Explicitly empty FPM values are passed through unchanged; they do not select the defaults. An empty status path disables FPM’s status page. Keep the ping path non-empty because an empty value can prevent FPM workers from starting. To disable the Apache status and ping routes, set ENABLE_FPM_STATUS=false.

Query them from inside the container:

Terminal window
docker exec app curl -s 'http://127.0.0.1/fpm-status?full'

These values are applied to web requests through the PHP-FPM pool. The CLI uses the variant php.ini settings. PHP_DISABLE_FUNCTIONS is passed to the PHP-FPM master on its command line instead, so it also applies to any pool you add. A pool can disable more functions with php_admin_value[disable_functions] but cannot re-enable the ones in the variable; change the variable instead (empty disables nothing). When the variable is removed from the container environment (-e PHP_DISABLE_FUNCTIONS or Compose environment: [PHP_DISABLE_FUNCTIONS] while it is unset on the host), the entrypoint applies the default list.

VariableDefault
PHP_ALLOW_URL_FOPEN0
PHP_ALLOW_URL_INCLUDE0
PHP_DATE_TIMEZONEUTC
PHP_DISABLE_FUNCTIONSexec,passthru,shell_exec,system,proc_open,popen
PHP_DISPLAY_ERRORS0
PHP_DISPLAY_STARTUP_ERRORS0
PHP_ERROR_LOG/proc/self/fd/2
PHP_ERROR_REPORTINGE_ALL & ~E_DEPRECATED
PHP_EXPOSE0
PHP_LOG_ERRORS1
PHP_MAX_EXECUTION_TIME30
PHP_MAX_FILE_UPLOADS20
PHP_MAX_INPUT_TIME60
PHP_MAX_INPUT_VARS1000
PHP_MEMORY_LIMIT256M
PHP_POST_MAX_SIZE50M
PHP_SESSION_HANDLERfiles
PHP_SESSION_PATH/run/yii2/sessions
PHP_UPLOAD_MAX_FILESIZE50M
VariableDefault
PHP_FPM_ACCESS_LOG/proc/self/fd/1
PHP_FPM_CATCH_OUTPUTyes
PHP_FPM_IDLE_TIMEOUT10s
PHP_FPM_LOG_LEVELwarning
PHP_FPM_MAX_CHILDREN50
PHP_FPM_MAX_REQUESTS500
PHP_FPM_MAX_SPARE35
PHP_FPM_MIN_SPARE5
PHP_FPM_PMdynamic
PHP_FPM_REQUEST_TIMEOUT30
PHP_FPM_RLIMIT_FILES131072
PHP_FPM_SLOWLOG_TIMEOUT5s
PHP_FPM_START_SERVERS5

Each variable maps to the pool directive of the same role (pm, pm.max_children, request_terminate_timeout, rlimit_files and so on). The pool keeps the container environment (clear_env = no), so PHP code reads every variable passed to the container.

Xdebug is loaded in dev and full only. The PHP-FPM pool keeps the container environment (clear_env = no), so XDEBUG_MODE reaches web requests as well as CLI commands. The image ships no Xdebug settings; configure it with the standard XDEBUG_MODE and XDEBUG_CONFIG environment variables:

Terminal window
docker run -d -p 127.0.0.1:8080:80 -v "$PWD":/var/www/app \
--add-host=host.docker.internal:host-gateway \
-e XDEBUG_MODE=debug \
-e XDEBUG_TRIGGER=1 \
-e XDEBUG_CONFIG="client_host=host.docker.internal client_port=9003" \
ghcr.io/yii2-extensions/apache:8.5-debian-dev

The IDE must listen on port 9003 and map /var/www/app to the local application root. Xdebug initiates the connection to the IDE; publishing container port 9003 is unnecessary. XDEBUG_TRIGGER=1 is a local development example; omit it and trigger selected requests with the XDEBUG_TRIGGER query parameter or cookie instead. Use XDEBUG_MODE=off when debugging is not required and XDEBUG_MODE=coverage for coverage runs. See testing for CLI coverage and usage examples for the distinction between web and CLI PHP settings.