diff --git a/000-default.conf b/000-default.conf index 9263580..ba3990b 100644 --- a/000-default.conf +++ b/000-default.conf @@ -13,10 +13,11 @@ # PHP-FPM handler - SetHandler "proxy:unix:/run/php/php8.5-fpm.sock|fcgi://localhost/" + SetHandler "proxy:unix:/run/php/php-fpm.sock|fcgi://localhost/" # Docker-friendly logging ErrorLog /proc/self/fd/2 CustomLog /proc/self/fd/1 combined + \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 72f489b..476f466 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,39 +1,37 @@ -FROM debian:trixie-20260316 +FROM php:8.5.8-fpm-trixie + +ARG PHP_REDIS_VERSION=6.3.0 WORKDIR /data -# Install base packages + Apache + PHP repo -RUN apt-get update && apt-get install -y \ - lsb-release \ - ca-certificates \ - curl \ - logrotate \ - ssl-cert \ - apache2 \ +# Install Apache + build deps for the PHP extensions we need +RUN apt-get update \ + && apt-get install -y --no-install-recommends \ + ca-certificates \ + logrotate \ + ssl-cert \ + apache2 \ + libzip-dev \ + libonig-dev \ + pkg-config \ + $PHPIZE_DEPS \ && echo "ServerName localhost" >> /etc/apache2/apache2.conf \ \ - # Add Sury PHP repo - && curl -sSLo /tmp/debsuryorg-archive-keyring.deb https://packages.sury.org/debsuryorg-archive-keyring.deb \ - && dpkg -i /tmp/debsuryorg-archive-keyring.deb \ - && echo "deb [signed-by=/usr/share/keyrings/deb.sury.org-php.gpg] https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list \ + # PHP extensions (mysqli/pdo_mysql, mbstring, zip, redis) + # xml + curl are already built into the base image + && docker-php-ext-install mysqli pdo_mysql mbstring zip \ + && pecl install redis-${PHP_REDIS_VERSION} \ + && docker-php-ext-enable redis \ \ - && apt-get update \ + # Keep the runtime shared libs the compiled extensions link against; + # only the -dev/headers packages and build toolchain get dropped below + && apt-mark manual libzip5 libonig5 \ \ - # Install PHP 8.5 + extensions - && apt-get install -y \ - php8.5 \ - php8.5-cli \ - php8.5-fpm \ - php8.5-mysql \ - php8.5-xml \ - php8.5-mbstring \ - php8.5-curl \ - php8.5-zip \ - php8.5-redis \ - \ - # Cleanup - && apt-get autoremove -y \ - && apt-get clean \ + # Drop the build-only toolchain and headers now that the extensions are built + && apt-get purge -y --auto-remove \ + $PHPIZE_DEPS \ + libzip-dev \ + libonig-dev \ && rm -rf /var/lib/apt/lists/* /tmp/* # Apache + PHP-FPM configuration + performance tuning @@ -45,9 +43,6 @@ RUN \ && a2dismod mpm_prefork \ && a2enmod mpm_event \ \ - # Enable PHP-FPM - && a2enconf php8.5-fpm \ - \ # Remote IP config && echo 'RemoteIPHeader X-Forwarded-For' > /etc/apache2/conf-available/remoteip.conf \ && echo 'RemoteIPTrustedProxy 127.0.0.1' >> /etc/apache2/conf-available/remoteip.conf \ @@ -64,57 +59,63 @@ RUN \ && a2enconf compression \ \ # KeepAlive tuning - && cat < /etc/apache2/conf-available/keepalive.conf -KeepAlive On -MaxKeepAliveRequests 100 -KeepAliveTimeout 2 -EOF \ + && printf '%s\n' \ + 'KeepAlive On' \ + 'MaxKeepAliveRequests 100' \ + 'KeepAliveTimeout 2' \ + > /etc/apache2/conf-available/keepalive.conf \ && a2enconf keepalive \ \ # MPM Event tuning - && cat < /etc/apache2/conf-available/mpm-event-tuning.conf - - StartServers 2 - MinSpareThreads 25 - MaxSpareThreads 75 - ThreadLimit 64 - ThreadsPerChild 25 - MaxRequestWorkers 150 - MaxConnectionsPerChild 1000 - -EOF \ + && printf '%s\n' \ + '' \ + ' StartServers 2' \ + ' MinSpareThreads 25' \ + ' MaxSpareThreads 75' \ + ' ThreadLimit 64' \ + ' ThreadsPerChild 25' \ + ' MaxRequestWorkers 150' \ + ' MaxConnectionsPerChild 1000' \ + '' \ + > /etc/apache2/conf-available/mpm-event-tuning.conf \ && a2enconf mpm-event-tuning \ \ # Logrotate - && cat < /etc/logrotate.d/apache2 -/var/log/apache2/*.log { - weekly - missingok - rotate 4 - compress - delaycompress - notifempty - create 640 root adm -} -EOF + && printf '%s\n' \ + '/var/log/apache2/*.log {' \ + ' weekly' \ + ' missingok' \ + ' rotate 4' \ + ' compress' \ + ' delaycompress' \ + ' notifempty' \ + ' create 640 root adm' \ + '}' \ + > /etc/logrotate.d/apache2 \ + \ + # PHP-FPM tuning (unix socket, to match the Apache vhost's proxy_fcgi handler) + && mkdir -p /run/php \ + && sed -i \ + -e 's|^;*listen = .*|listen = /run/php/php-fpm.sock|' \ + -e 's/^;*listen.owner = .*/listen.owner = www-data/' \ + -e 's/^;*listen.group = .*/listen.group = www-data/' \ + -e 's/^;*listen.mode = .*/listen.mode = 0660/' \ + -e 's/^pm = .*/pm = dynamic/' \ + -e 's/^pm.max_children = .*/pm.max_children = 20/' \ + -e 's/^pm.start_servers = .*/pm.start_servers = 2/' \ + -e 's/^pm.min_spare_servers = .*/pm.min_spare_servers = 2/' \ + -e 's/^pm.max_spare_servers = .*/pm.max_spare_servers = 5/' \ + /usr/local/etc/php-fpm.d/www.conf -# PHP-FPM tuning -RUN sed -i 's/^pm = .*/pm = dynamic/' /etc/php/8.5/fpm/pool.d/www.conf && \ - sed -i 's/^pm.max_children = .*/pm.max_children = 20/' /etc/php/8.5/fpm/pool.d/www.conf && \ - sed -i 's/^pm.start_servers = .*/pm.start_servers = 2/' /etc/php/8.5/fpm/pool.d/www.conf && \ - sed -i 's/^pm.min_spare_servers = .*/pm.min_spare_servers = 2/' /etc/php/8.5/fpm/pool.d/www.conf && \ - sed -i 's/^pm.max_spare_servers = .*/pm.max_spare_servers = 5/' /etc/php/8.5/fpm/pool.d/www.conf - -# PHP custom config -RUN mkdir -p /php && echo "PHP_INI_SCAN_DIR=/php" > /etc/environment +# PHP custom config — /php is layered in front of the image's default conf.d +ENV PHP_INI_SCAN_DIR="/php:${PHP_INI_DIR}/conf.d" COPY php.ini /php/php.ini COPY 000-default.conf /etc/apache2/sites-available/000-default.conf +COPY --chmod=755 start.sh /start.sh + +RUN a2ensite 000-default EXPOSE 80 -# Startup -COPY start.sh /start.sh -RUN chmod +x /start.sh - -CMD ["/start.sh"] \ No newline at end of file +CMD ["/start.sh"] diff --git a/README.md b/README.md index 0bd38f0..729bcb2 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,8 @@ It provides a streamlined stack featuring Apache, the latest PHP version, Redis, ## Features -- **PHP Version**: 8.5.3 +- **Base**: official `php:8.5.8-fpm-trixie` image (Debian Trixie) +- **PHP Version**: 8.5.8 (pinned) - **Apache Web Server**: Configured to run PHP applications - **Support for**: - `remoteip` (reverse proxy) @@ -33,9 +34,9 @@ cd corxn ```bash sudo su -docker buildx build --no-cache -t 4lights/corxn:8.5.3 -t 4lights/corxn:latest --load . +docker buildx build --no-cache -t 4lights/corxn:8.5.8 -t 4lights/corxn:latest --load . docker login -u -docker push 4lights/corxn:8.5.3 +docker push 4lights/corxn:8.5.8 docker push 4lights/corxn:latest ``` # Testing diff --git a/docker-compose.yml b/docker-compose.yml index 66ac80a..5eb6e35 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,7 @@ # Sample Docker Compose services: corxn: - image: 4lights/corxn:latest + image: 4lights/corxn:8.5.8 ports: - "8000:80" volumes: diff --git a/start.sh b/start.sh index c2db930..8d1a8dc 100644 --- a/start.sh +++ b/start.sh @@ -1,6 +1,6 @@ #!/bin/bash set -e -service php8.5-fpm start +php-fpm -D -exec apachectl -D FOREGROUND \ No newline at end of file +exec apachectl -D FOREGROUND