php version 8.4.5 debian rebuild v6

This commit is contained in:
2025-03-15 00:38:49 -07:00
parent 125e461786
commit c8021f204d
8 changed files with 350 additions and 236 deletions

View File

@@ -1,70 +1,53 @@
#################################################################################################################################
# Project: https://git.4lt.ca/4lt/phpcontainer/
# v 5.0.1
#################################################################################################################################
FROM debian:bookworm-20250224
FROM php:8.4.2-apache
# Set maintainer information
LABEL version="5.0.1"
LABEL maintainer="4 Lights Consulting <info@4lt.ca>"
LABEL description="Production-ready PHP Apache container"
LABEL org.label-schema.vcs-url="https://git.4lt.ca/4lt/phpcontainer"
# Set working directory and Apache document root
WORKDIR /data
ENV APACHE_DOCUMENT_ROOT=/data/public/
# Update and install required packages
RUN set -eux; \
# Install necessary packages and configure PHP repository
RUN apt-get update && apt-get install -y \
lsb-release ca-certificates curl apt-transport-https logrotate ssl-cert apache2 && \
echo "ServerName localhost" >> /etc/apache2/apache2.conf && \
curl -sSLo /tmp/debsuryorg-archive-keyring.deb https://packages.sury.org/debsuryorg-archive-keyring.deb && \
dpkg -i /tmp/debsuryorg-archive-keyring.deb && \
sh -c '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' && \
apt-get update && \
apt-get install -y --no-install-recommends \
ghostscript \
libssl-dev \
libbz2-dev \
libfreetype6-dev \
libjpeg-dev \
libpng-dev \
libwebp-dev \
libzip-dev && \
rm -rf /var/lib/apt/lists/*
apt-get install -y \
php8.4 php8.4-cli php8.4-fpm php8.4-mysql php8.4-xml php8.4-mbstring php8.4-curl php8.4-zip php8.4-redis libapache2-mod-php8.4 && \
apt-get autoremove -y && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* /tmp/*
# Configure and install essential PHP extensions
RUN set -ex; \
docker-php-ext-configure gd --with-freetype --with-jpeg --with-webp; \
docker-php-ext-install -j "$(nproc)" \
bz2 \
gd \
mysqli \
pdo_mysql \
zip
# log management
RUN cat <<EOF > /etc/logrotate.d/apache2
/var/log/apache2/*.log {
weekly
missingok
rotate 4
compress
delaycompress
notifempty
create 640 root adm
}
EOF
# Set recommended PHP.ini settings
RUN set -eux; \
echo 'opcache.memory_consumption=128' > /usr/local/etc/php/conf.d/opcache-recommended.ini; \
echo 'opcache.interned_strings_buffer=8' >> /usr/local/etc/php/conf.d/opcache-recommended.ini; \
echo 'opcache.max_accelerated_files=4000' >> /usr/local/etc/php/conf.d/opcache-recommended.ini; \
echo 'opcache.revalidate_freq=2' >> /usr/local/etc/php/conf.d/opcache-recommended.ini; \
echo 'opcache.fast_shutdown=1' >> /usr/local/etc/php/conf.d/opcache-recommended.ini; \
echo 'error_reporting = E_ERROR | E_WARNING | E_PARSE | E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_COMPILE_WARNING | E_RECOVERABLE_ERROR' > /usr/local/etc/php/conf.d/error-logging.ini; \
echo 'display_errors = Off' >> /usr/local/etc/php/conf.d/error-logging.ini; \
echo 'log_errors = On' >> /usr/local/etc/php/conf.d/error-logging.ini; \
echo 'error_log = /dev/stderr' >> /usr/local/etc/php/conf.d/error-logging.ini
# Enable Apache modules and configure RemoteIP
RUN set -eux; \
a2enmod expires headers rewrite remoteip socache_shmcb ssl; \
echo 'RemoteIPHeader X-Forwarded-For' > /etc/apache2/conf-available/remoteip.conf; \
echo 'RemoteIPTrustedProxy 10.0.0.0/8' >> /etc/apache2/conf-available/remoteip.conf; \
echo 'RemoteIPTrustedProxy 172.16.0.0/12' >> /etc/apache2/conf-available/remoteip.conf; \
echo 'RemoteIPTrustedProxy 192.168.0.0/16' >> /etc/apache2/conf-available/remoteip.conf; \
a2enconf remoteip; \
RUN echo 'RemoteIPHeader X-Forwarded-For' > /etc/apache2/conf-available/remoteip.conf && \
echo 'RemoteIPTrustedProxy 127.0.0.1' >> /etc/apache2/conf-available/remoteip.conf && \
a2enconf remoteip && \
sed -ri 's/([[:space:]]*LogFormat[[:space:]]+"[^"]*)%h([^"]*")/\1%a\2/g' /etc/apache2/*.conf
# More Apache settings
RUN sed -ri -e 's!/var/www/html!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/sites-available/*.conf
RUN sed -ri -e 's!/var/www/!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf
RUN echo "ServerName localhost" >> /etc/apache2/apache2.conf
RUN mkdir -p /php && echo "PHP_INI_SCAN_DIR=/php" > /etc/environment
COPY php.ini /php/php.ini
COPY 000-default.conf /etc/apache2/sites-available/000-default.conf
# Security headers for Apache
RUN echo 'Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"' >> /etc/apache2/conf-available/security.conf && \
echo 'Header always set X-Content-Type-Options "nosniff"' >> /etc/apache2/conf-available/security.conf && \
echo 'Header always set X-XSS-Protection "1; mode=block"' >> /etc/apache2/conf-available/security.conf && \
echo 'Header always set X-Frame-Options "SAMEORIGIN"' >> /etc/apache2/conf-available/security.conf
RUN a2enmod expires headers rewrite remoteip socache_shmcb ssl
EXPOSE 80
CMD ["apache2-foreground"]
CMD ["apachectl", "-D", "FOREGROUND"]
HEALTHCHECK --interval=30s --timeout=10s --retries=3 \
CMD curl --silent --fail localhost:80 || exit 1