diff --git a/.dockerignore b/.dockerignore index 286758a..3cb5182 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,2 +1,3 @@ .secrets -.act \ No newline at end of file +.act +examples diff --git a/.gitignore b/.gitignore index 1f4f0a3..7e0dc53 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +pkg .secrets .idea .vscode diff --git a/Dockerfile b/Dockerfile index e1861af..76c3b2b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,65 +1,80 @@ -FROM alpine:3.17 +# Install Caddy +FROM docker.io/caddy:builder-alpine AS caddy-builder +RUN xcaddy build + + +# Install PHP +FROM docker.io/alpine LABEL maintainer="vladimir@hodakov.me" +# Setup document root +WORKDIR /var/www/html + +# Get caddy +COPY --from=caddy-builder /usr/bin/caddy /usr/bin/caddy + +# Install packages and remove default server definition RUN apk add --no-cache curl \ imagemagick \ - apache2 \ - php81 \ - php81-apache2 \ - php81-ctype \ - php81-curl \ - php81-dom \ - php81-ftp \ - php81-gd \ - php81-iconv \ - php81-json \ - php81-mbstring \ - php81-mysqli \ - php81-opcache \ - php81-openssl \ - php81-pgsql \ - php81-sqlite3 \ - php81-tokenizer \ - php81-xml \ - php81-zlib \ - php81-zip \ - su-exec + php84 \ + php84-fpm \ + php84-apache2 \ + php84-ctype \ + php84-curl \ + php84-dom \ + php84-ftp \ + php84-gd \ + php84-iconv \ + php84-json \ + php84-mbstring \ + php84-mysqli \ + php84-opcache \ + php84-openssl \ + php84-pgsql \ + php84-sqlite3 \ + php84-tokenizer \ + php84-xml \ + php84-zlib \ + php84-zip \ + supervisor -### phpBB -ENV PHPBB_VERSION 3.3.14 -ENV PHPBB_SHA256 68cd6cf3faefa175ea3892ba02c6b112e8967ed33703521c79820e35bd15ec9a +# Configure Caddy +COPY config/Caddyfile /etc/caddy/Caddyfile + +# Configure PHP-FPM +COPY config/fpm-pool.conf /etc/php84/php-fpm.d/www.conf +COPY config/php.ini /etc/php84/conf.d/custom.ini + +# Configure supervisord +COPY config/supervisord.conf /etc/supervisor/conf.d/supervisord.conf + +RUN mkdir /.config /phpbb + +# Add tests app installation +COPY src/ /var/www/html/ + +# Add phpBB installation +ENV PHPBB_VERSION=3.3.14 +ENV PHPBB_SHA256=68cd6cf3faefa175ea3892ba02c6b112e8967ed33703521c79820e35bd15ec9a WORKDIR /tmp RUN curl -SL https://download.phpbb.com/pub/release/3.3/${PHPBB_VERSION}/phpBB-${PHPBB_VERSION}.tar.bz2 -o phpbb.tar.bz2 \ && echo "${PHPBB_SHA256} phpbb.tar.bz2" | sha256sum -c - \ && tar -xjf phpbb.tar.bz2 \ - && mkdir /phpbb \ && mkdir /phpbb/sqlite \ && mv phpBB3 /phpbb/www \ && rm -f phpbb.tar.bz2 COPY phpbb/config.php /phpbb/www -### Server -RUN mkdir -p /run/apache2 /phpbb/opcache \ - && chown apache:apache /run/apache2 /phpbb/opcache +# Expose the ports Caddy is reachable on +EXPOSE 8080 +EXPOSE 8181 -COPY apache2/httpd.conf /etc/apache2/ -COPY apache2/conf.d/* /etc/apache2/conf.d/ -COPY php/php.ini php/php-cli.ini /etc/php81/ -COPY php/conf.d/* /etc/php81/conf.d -COPY start.sh /usr/local/bin/ - -RUN chown -R apache:apache /phpbb WORKDIR /phpbb/www -#VOLUME /phpbb/sqlite -#VOLUME /phpbb/www/files -#VOLUME /phpbb/www/store -#VOLUME /phpbb/www/images/avatars/upload - ENV PHPBB_INSTALL= \ PHPBB_DB_DRIVER=sqlite3 \ PHPBB_DB_HOST=/phpbb/sqlite/sqlite.db \ @@ -73,5 +88,8 @@ ENV PHPBB_INSTALL= \ PHPBB_DEBUG= \ PHPBB_DEBUG_CONTAINER= -EXPOSE 80 +COPY start.sh /usr/local/bin/ CMD ["start.sh"] + +# Configure a healthcheck to validate that everything is up and running +HEALTHCHECK --timeout=10s CMD curl --silent --fail http://127.0.0.1:8080/fpm-ping diff --git a/LICENSE b/LICENSE index d189906..6a04821 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,7 @@ MIT License Copyright (c) 2016 Seleznyov Dmitry +Copyright (c) 2023-2025 Vladimir Hodakov Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.MD b/README.MD index c04c034..701bb94 100644 --- a/README.MD +++ b/README.MD @@ -2,26 +2,28 @@ This is updated fork of [selim13's docker-phpbb image](https://github.com/selim13/docker-phpbb). +Now it even bundles caddy instead of apache2. Thanks +[ParaParty/docker-php-caddy](https://github.com/ParaParty/docker-php-caddy) for the inspiration. + Lightweight, Alpine based [phpBB](https://www.phpbb.com/) docker image. # Supported tags and respective `Dockerfile` links -- [`3.3`, `3.3.4`, `latest`](https://github.com/selim13/docker-phpbb/blob/master/Dockerfile) bundled with PHP 8 -- [`3.2`, `3.2.11`](https://github.com/selim13/docker-phpbb/blob/3.2-alpine-apache/Dockerfile) bundled with PHP 7.2 +- [`3.3`, `3.3.11`, `latest`](https://github.com/fat0troll/docker-phpbb/blob/master/Dockerfile) bundled with PHP 8 # How to use this image ## Initial installation -If you don't have a prepared phpBB database, you can use a standard phpBB -installer script, just run a temporary container with `PHPBB_INSTALL=true` +If you don't have a prepared phpBB database, you can use a standard phpBB +installer script, just run a temporary container with `PHPBB_INSTALL=true` environment variable: ```console -$ docker run -p 8000:80 --name phpbb-install -e PHPBB_INSTALL=true -d selim13/phpbb:3.3 +$ docker run -p 8000:8181 --name phpbb-install -e PHPBB_INSTALL=true -d fat0troll/phpbb:3.3 ``` -Point your browser to the http://localhost:8000 to begin the +Point your browser to the http://localhost:8000 to begin the installation process. This image is bundled with SQLite3, MySQL and PostgresSQL database engines @@ -33,7 +35,7 @@ For SQLite3 set `Database server hostname or DSN` field to `/phpbb/sqlite/sqlite This file will be created on a docker volume and outside of the webserver's document root for security. Leave user name, password and database name fields blank. -After the installation process is complete you can safely stop this container: +After the installation process is complete you can safely stop this container: ```console $ docker stop phpbb-install @@ -43,9 +45,8 @@ $ docker stop phpbb-install You can start a container as follows: - ```console -$ docker run --name phpbb -d selim13/phpbb:3.3 +$ docker run --name phpbb -d fat0troll/phpbb:3.3 ``` By default, it uses SQLite3 as a database backend, so you will need to supply @@ -54,7 +55,7 @@ it with a database file. It's default path is `/phpbb/sqlite/sqlite.db`. You can import it from the temporary installation container above: ```console -$ docker run --volumes-from phpbb-install --name phpbb -d selim13/phpbb:3.3 +$ docker run --volumes-from phpbb-install --name phpbb -d fat0troll/phpbb:3.3 ``` Or just copy it inside container if you have one from previous phpBB @@ -77,19 +78,21 @@ $ docker run --name phpbb \ -e PHPBB_DB_PASSWD=pass -d selim13/phpbb:3.3 ``` -## Environment variables +## Environment variables This image utilises environment variables for basic configuration. Most of them are passed directly to phpBB's `config.php` or to the startup script. ### PHPBB_INSTALL + If set to `true`, container will start with an empty `config.php` file and -phpBB `/install/` directory intact. This will allow you to initilalize +phpBB `/install/` directory intact. This will allow you to initilalize a forum database upon fresh installation. ### PHPBB_DB_DRIVER Selects a database driver. phpBB3 ships with following drivers: + - `mssql` - MS SQL Server - `mysql` - MySQL via outdated php extension - `mysqli` - MySQL via newer php extension @@ -101,15 +104,15 @@ Selects a database driver. phpBB3 ships with following drivers: This image is bundled with support of `sqlite3`, `mysqli` and `postgres` drivers. Default value: sqlite3 - + ### PHPBB_DB_HOST Database hostname or ip address. -For the SQLite3 driver sets database file path. +For the SQLite3 driver sets database file path. Default value: /phpbb/sqlite/sqlite.db - + ### PHPBB_DB_PORT Database port. @@ -134,7 +137,7 @@ or by extending this image. Table prefix for phpBB3 database. -Default value: phpbb_ +Default value: phpbb\_ ### PHPBB_DB_AUTOMIGRATE @@ -144,6 +147,7 @@ executing `bin/phpbbcli.php db:migrate` on every startup. If migrations fail, container will refuse to start. ### PHPBB_DB_WAIT + If set to `true`, container will wait for database service to become available. You will need to explicitly set `PHPBB_DB_HOST` and `PHPBB_DB_PORT` for this to work. @@ -151,7 +155,7 @@ to work. Use in conjunction with `PHPBB_DB_AUTOMIGRATE` to prevent running migrations before database is ready. -Won't work for SQLite database engine as it is always available. +Won't work for SQLite database engine as it is always available. ### PHPBB_DISPLAY_LOAD_TIME @@ -163,10 +167,11 @@ usage at the bottom of the page. If set to `true`, enables phpBB debug mode. ### PHPBB_DEBUG_CONTAINER - + ## Volumes By default there are four volumes created for each container: + - /phpbb/sqlite - /phpbb/www/files - /phpbb/www/store @@ -175,12 +180,12 @@ By default there are four volumes created for each container: # Additional configuration This image is based on a stock official Alpine image with apache2 and php5 -packages from the Alpine Linux repository, so you can drop their custom +packages from the Alpine Linux repository, so you can drop their custom configuration files to `/etc/apache2/conf.d` and `/etc/php5/conf.d`. ## Pass user's IP from proxy -If you are planning to start a container behind proxy +If you are planning to start a container behind proxy (like [nginx-proxy](https://github.com/jwilder/nginx-proxy)), it will probably be a good idea to get user's real IP instead of proxy one. For this, you can use Apache RemoteIP module. Create a configuration file: diff --git a/apache2/conf.d/mpm.conf b/apache2/conf.d/mpm.conf deleted file mode 100644 index d96dfb1..0000000 --- a/apache2/conf.d/mpm.conf +++ /dev/null @@ -1,9 +0,0 @@ -PidFile "/run/apache2/httpd.pid" - - - StartServers 5 - MinSpareServers 5 - MaxSpareServers 10 - MaxRequestWorkers 250 - MaxConnectionsPerChild 0 - \ No newline at end of file diff --git a/apache2/httpd.conf b/apache2/httpd.conf deleted file mode 100644 index 862a9b5..0000000 --- a/apache2/httpd.conf +++ /dev/null @@ -1,155 +0,0 @@ -ServerTokens Prod - -ServerRoot /var/www - -Listen 80 - -LoadModule authn_file_module modules/mod_authn_file.so -#LoadModule authn_dbm_module modules/mod_authn_dbm.so -#LoadModule authn_anon_module modules/mod_authn_anon.so -#LoadModule authn_dbd_module modules/mod_authn_dbd.so -#LoadModule authn_socache_module modules/mod_authn_socache.so -LoadModule authn_core_module modules/mod_authn_core.so -LoadModule authz_host_module modules/mod_authz_host.so -LoadModule authz_groupfile_module modules/mod_authz_groupfile.so -LoadModule authz_user_module modules/mod_authz_user.so -#LoadModule authz_dbm_module modules/mod_authz_dbm.so -#LoadModule authz_owner_module modules/mod_authz_owner.so -#LoadModule authz_dbd_module modules/mod_authz_dbd.so -LoadModule authz_core_module modules/mod_authz_core.so -LoadModule access_compat_module modules/mod_access_compat.so -LoadModule auth_basic_module modules/mod_auth_basic.so -#LoadModule auth_form_module modules/mod_auth_form.so -#LoadModule auth_digest_module modules/mod_auth_digest.so -#LoadModule allowmethods_module modules/mod_allowmethods.so -#LoadModule file_cache_module modules/mod_file_cache.so -#LoadModule cache_module modules/mod_cache.so -#LoadModule cache_disk_module modules/mod_cache_disk.so -#LoadModule cache_socache_module modules/mod_cache_socache.so -#LoadModule socache_shmcb_module modules/mod_socache_shmcb.so -#LoadModule socache_dbm_module modules/mod_socache_dbm.so -#LoadModule socache_memcache_module modules/mod_socache_memcache.so -#LoadModule watchdog_module modules/mod_watchdog.so -#LoadModule macro_module modules/mod_macro.so -#LoadModule dbd_module modules/mod_dbd.so -#LoadModule dumpio_module modules/mod_dumpio.so -#LoadModule echo_module modules/mod_echo.so -#LoadModule buffer_module modules/mod_buffer.so -#LoadModule data_module modules/mod_data.so -#LoadModule ratelimit_module modules/mod_ratelimit.so -LoadModule reqtimeout_module modules/mod_reqtimeout.so -#LoadModule ext_filter_module modules/mod_ext_filter.so -#LoadModule request_module modules/mod_request.so -#LoadModule include_module modules/mod_include.so -LoadModule filter_module modules/mod_filter.so -#LoadModule reflector_module modules/mod_reflector.so -#LoadModule substitute_module modules/mod_substitute.so -#LoadModule sed_module modules/mod_sed.so -#LoadModule charset_lite_module modules/mod_charset_lite.so -#LoadModule deflate_module modules/mod_deflate.so -LoadModule mime_module modules/mod_mime.so -LoadModule log_config_module modules/mod_log_config.so -#LoadModule log_debug_module modules/mod_log_debug.so -#LoadModule log_forensic_module modules/mod_log_forensic.so -#LoadModule logio_module modules/mod_logio.so -LoadModule env_module modules/mod_env.so -#LoadModule mime_magic_module modules/mod_mime_magic.so -#LoadModule expires_module modules/mod_expires.so -LoadModule headers_module modules/mod_headers.so -#LoadModule usertrack_module modules/mod_usertrack.so -#LoadModule unique_id_module modules/mod_unique_id.so -LoadModule setenvif_module modules/mod_setenvif.so -LoadModule version_module modules/mod_version.so -#LoadModule remoteip_module modules/mod_remoteip.so -#LoadModule session_module modules/mod_session.so -#LoadModule session_cookie_module modules/mod_session_cookie.so -#LoadModule session_dbd_module modules/mod_session_dbd.so -#LoadModule slotmem_shm_module modules/mod_slotmem_shm.so -#LoadModule slotmem_plain_module modules/mod_slotmem_plain.so -#LoadModule dialup_module modules/mod_dialup.so -#LoadModule mpm_event_module modules/mod_mpm_event.so -LoadModule mpm_prefork_module modules/mod_mpm_prefork.so -#LoadModule mpm_worker_module modules/mod_mpm_worker.so -LoadModule unixd_module modules/mod_unixd.so -#LoadModule heartbeat_module modules/mod_heartbeat.so -#LoadModule heartmonitor_module modules/mod_heartmonitor.so -LoadModule status_module modules/mod_status.so -#LoadModule autoindex_module modules/mod_autoindex.so -#LoadModule asis_module modules/mod_asis.so -#LoadModule info_module modules/mod_info.so -#LoadModule suexec_module modules/mod_suexec.so - - #LoadModule cgid_module modules/mod_cgid.so - - - #LoadModule cgi_module modules/mod_cgi.so - -#LoadModule vhost_alias_module modules/mod_vhost_alias.so -#LoadModule negotiation_module modules/mod_negotiation.so -LoadModule dir_module modules/mod_dir.so -#LoadModule actions_module modules/mod_actions.so -#LoadModule speling_module modules/mod_speling.so -#LoadModule userdir_module modules/mod_userdir.so -LoadModule alias_module modules/mod_alias.so -LoadModule rewrite_module modules/mod_rewrite.so - -LoadModule negotiation_module modules/mod_negotiation.so - - - User apache - Group apache - - - -ServerAdmin you@example.com - -ServerSignature Off - -#ServerName www.example.com:80 - - - AllowOverride none - Require all denied - - -DocumentRoot "/phpbb/www" - - Options FollowSymLinks - AllowOverride All - Require all granted - - # Return 404 for all dot files (.htaccess, .git, etc...) - RedirectMatch 404 /\..*$ - - - - DirectoryIndex index.php index.html - - - - Require all denied - - -ErrorLog /dev/stderr -LogLevel warn - - - LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined - LogFormat "%h %l %u %t \"%r\" %>s %b" common - - CustomLog /dev/stdout combined - - - - - TypesConfig /etc/apache2/mime.types - AddType application/x-compress .Z - AddType application/x-gzip .gz .tgz - - - - - MIMEMagicFile /etc/apache2/magic - - -IncludeOptional /etc/apache2/conf.d/*.conf diff --git a/config/Caddyfile b/config/Caddyfile new file mode 100644 index 0000000..f22d5e1 --- /dev/null +++ b/config/Caddyfile @@ -0,0 +1,23 @@ +:8080 { + root * /var/www/html/public + + php_fastcgi unix//run/php-fpm.sock { + trusted_proxies private_ranges + } + + file_server + + log stdout +} + +:8181 { + root * /phpbb/www + + php_fastcgi unix//run/php-fpm.sock { + trusted_proxies private_ranges + } + + file_server + + log stdout +} diff --git a/config/fpm-pool.conf b/config/fpm-pool.conf new file mode 100644 index 0000000..4be2061 --- /dev/null +++ b/config/fpm-pool.conf @@ -0,0 +1,56 @@ +[global] +; Log to stderr +error_log = /dev/stderr + +[www] +; The address on which to accept FastCGI requests. +; Valid syntaxes are: +; 'ip.add.re.ss:port' - to listen on a TCP socket to a specific IPv4 address on +; a specific port; +; '[ip:6:addr:ess]:port' - to listen on a TCP socket to a specific IPv6 address on +; a specific port; +; 'port' - to listen on a TCP socket to all addresses +; (IPv6 and IPv4-mapped) on a specific port; +; '/path/to/unix/socket' - to listen on a unix socket. +; Note: This value is mandatory. +listen = /run/php-fpm.sock + +; Enable status page +pm.status_path = /fpm-status + +; Ondemand process manager +pm = ondemand + +; The number of child processes to be created when pm is set to 'static' and the +; maximum number of child processes when pm is set to 'dynamic' or 'ondemand'. +; This value sets the limit on the number of simultaneous requests that will be +; served. Equivalent to the ApacheMaxClients directive with mpm_prefork. +; Equivalent to the PHP_FCGI_CHILDREN environment variable in the original PHP +; CGI. The below defaults are based on a server without much resources. Don't +; forget to tweak pm.* to fit your needs. +; Note: Used when pm is set to 'static', 'dynamic' or 'ondemand' +; Note: This value is mandatory. +pm.max_children = 100 + +; The number of seconds after which an idle process will be killed. +; Note: Used only when pm is set to 'ondemand' +; Default Value: 10s +pm.process_idle_timeout = 10s; + +; The number of requests each child process should execute before respawning. +; This can be useful to work around memory leaks in 3rd party libraries. For +; endless request processing specify '0'. Equivalent to PHP_FCGI_MAX_REQUESTS. +; Default Value: 0 +pm.max_requests = 1000 + +; Make sure the FPM workers can reach the environment variables for configuration +clear_env = no + +; Catch output from PHP +catch_workers_output = yes + +; Remove the 'child 10 said into stderr' prefix in the log and only show the actual message +decorate_workers_output = no + +; Enable ping page to use in healthcheck +ping.path = /fpm-ping diff --git a/config/php.ini b/config/php.ini new file mode 100644 index 0000000..7bb1be5 --- /dev/null +++ b/config/php.ini @@ -0,0 +1,2 @@ +[Date] +date.timezone="UTC" diff --git a/config/supervisord.conf b/config/supervisord.conf new file mode 100644 index 0000000..e1192bb --- /dev/null +++ b/config/supervisord.conf @@ -0,0 +1,24 @@ +[supervisord] +nodaemon=true +user=root +logfile=/dev/null +logfile_maxbytes=0 +pidfile=/run/supervisord.pid + +[program:php-fpm] +command=php-fpm84 -F -R +stdout_logfile=/dev/stdout +stdout_logfile_maxbytes=0 +stderr_logfile=/dev/stderr +stderr_logfile_maxbytes=0 +autorestart=false +startretries=0 + +[program:caddy] +command=caddy run --config /etc/caddy/Caddyfile +stdout_logfile=/dev/stdout +stdout_logfile_maxbytes=0 +stderr_logfile=/dev/stderr +stderr_logfile_maxbytes=0 +autorestart=false +startretries=0 diff --git a/docker-compose.test.yml b/docker-compose.test.yml new file mode 100644 index 0000000..ae8a05b --- /dev/null +++ b/docker-compose.test.yml @@ -0,0 +1,12 @@ +version: '3.5' +services: + app: + image: ${IMAGE_NAME}:${IMAGE_TAG} + build: . + sut: + image: alpine:3.13 + depends_on: + - app + command: /tmp/run_tests.sh + volumes: + - "./run_tests.sh:/tmp/run_tests.sh:ro" diff --git a/docker-compose.build.yml b/examples/docker-compose.build.yml similarity index 100% rename from docker-compose.build.yml rename to examples/docker-compose.build.yml diff --git a/docker-compose.yml b/examples/docker-compose.yml similarity index 100% rename from docker-compose.yml rename to examples/docker-compose.yml diff --git a/php/conf.d/opcache.ini b/php/conf.d/opcache.ini deleted file mode 100644 index c6ea98d..0000000 --- a/php/conf.d/opcache.ini +++ /dev/null @@ -1,8 +0,0 @@ -opcache.memory_consumption=64 -opcache.interned_strings_buffer=8 -opcache.max_accelerated_files=4000 -opcache.validate_timestamps=0 -opcache.revalidate_freq=0 -opcache.fast_shutdown=1 -opcache.enable_cli=1 -opcache.file_cache=/phpbb/opcache \ No newline at end of file diff --git a/php/php-cli.ini b/php/php-cli.ini deleted file mode 100644 index 2d0627a..0000000 --- a/php/php-cli.ini +++ /dev/null @@ -1,2 +0,0 @@ -[php] -memory_limit = -1 diff --git a/php/php.ini b/php/php.ini deleted file mode 100644 index 89b7bb0..0000000 --- a/php/php.ini +++ /dev/null @@ -1,18 +0,0 @@ -[PHP] -file_uploads = On -max_file_uploads = 2 -upload_max_filesize = 8M -post_max_size = 8M - -allow_url_fopen = On - -expose_php = Off -security.limit_extensions = .php - -output_buffering = On -display_errors = Off -log_errors = On -error_log = /dev/stderr - -[Date] -date.timezone = 'UTC' \ No newline at end of file diff --git a/run_tests.sh b/run_tests.sh new file mode 100644 index 0000000..39689fe --- /dev/null +++ b/run_tests.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env sh +apk --no-cache add curl +curl --silent --fail http://app:8080 | grep 'PHP 8.1' diff --git a/src/public/index.php b/src/public/index.php new file mode 100644 index 0000000..61ace19 --- /dev/null +++ b/src/public/index.php @@ -0,0 +1,2 @@ +