67 lines
2.8 KiB
Docker
67 lines
2.8 KiB
Docker
# Use the PHP base image
|
|
FROM php:8.4.2-apache
|
|
|
|
# Set maintainer information
|
|
LABEL version="5.0.0"
|
|
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; \
|
|
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/*
|
|
|
|
# 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
|
|
|
|
# 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; \
|
|
sed -ri 's/([[:space:]]*LogFormat[[:space:]]+"[^"]*)%h([^"]*")/\1%a\2/g' /etc/apache2/*.conf
|
|
|
|
# Configure Apache document root
|
|
RUN sed -ri -e 's!/var/www/html!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/sites-available/*.conf; \
|
|
echo "ServerName localhost" >> /etc/apache2/apache2.conf
|
|
|
|
# Expose port and set command
|
|
EXPOSE 80
|
|
CMD ["apache2-foreground"]
|