FROM php:8.4.14-apache

# Enable Apache modules and custom config as root during build
RUN a2enmod rewrite headers

# GD extension - used by /publiser to resize/recompress uploaded images
RUN apt-get update \
    && apt-get install -y --no-install-recommends libjpeg62-turbo-dev libpng-dev libwebp-dev \
    && docker-php-ext-configure gd --with-jpeg --with-webp \
    && docker-php-ext-install gd \
    && rm -rf /var/lib/apt/lists/*

COPY apache.conf /etc/apache2/conf-available/custom.conf
RUN a2enconf custom

# Override default security.conf settings
RUN sed -i 's/^ServerTokens OS/ServerTokens Prod/' /etc/apache2/conf-available/security.conf \
    && sed -i 's/^ServerSignature On/ServerSignature Off/' /etc/apache2/conf-available/security.conf

# Log to /proc/self/fd for container output
RUN sed -i 's|ErrorLog.*|ErrorLog /proc/self/fd/2|' /etc/apache2/sites-available/000-default.conf \
    && sed -i 's|CustomLog.*|CustomLog /proc/self/fd/1 combined|' /etc/apache2/sites-available/000-default.conf \
    && sed -i 's|ErrorLog.*|ErrorLog /proc/self/fd/2|' /etc/apache2/apache2.conf
