FROM php:8.3-apache

RUN apt-get update \
    && apt-get install -y --no-install-recommends libcurl4-openssl-dev libsqlite3-dev libzip-dev \
    && docker-php-ext-install curl pdo_mysql pdo_sqlite zip \
    && a2enmod rewrite headers expires deflate \
    && rm -rf /var/lib/apt/lists/*

ENV APACHE_DOCUMENT_ROOT=/var/www/html/public
RUN sed -ri 's!/var/www/html!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/sites-available/*.conf /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf \
    && printf '%s\n' 'ServerTokens Prod' 'ServerSignature Off' > /etc/apache2/conf-available/security-local.conf \
    && a2enconf security-local

RUN printf '%s\n' 'display_errors=Off' 'log_errors=On' 'expose_php=Off' 'session.use_strict_mode=1' > /usr/local/etc/php/conf.d/cms-production.ini

WORKDIR /var/www/html
COPY . .
RUN mkdir -p storage/cache storage/logs storage/media storage/themes \
    && chown -R www-data:www-data storage \
    && chmod 700 storage storage/cache storage/logs storage/media storage/themes

HEALTHCHECK --interval=30s --timeout=5s --retries=3 CMD php -r '$b=@file_get_contents("http://127.0.0.1/api/health"); exit($b!==false&&str_contains($b,"\"status\":\"ok\"")?0:1);'
