FROM php:8.2-apache

ENV APP_ENV=production

WORKDIR /var/www/html

RUN apt-get update \
    && apt-get install -y --no-install-recommends libpq-dev libsqlite3-dev poppler-utils tesseract-ocr \
    && docker-php-ext-install pdo_pgsql pdo_sqlite opcache \
    && rm -rf /var/lib/apt/lists/*

COPY . .

RUN mkdir -p /var/www/html/uploads \
    && chown -R www-data:www-data /var/www/html/uploads \
    && chmod 775 /var/www/html/uploads \
    && printf '%s\n' \
        'upload_max_filesize=10M' \
        'post_max_size=32M' \
        'max_file_uploads=5' \
        'expose_php=0' \
        'display_errors=0' \
        'log_errors=1' \
        'session.use_strict_mode=1' \
        'session.use_only_cookies=1' \
        'session.cookie_httponly=1' \
        'session.cookie_secure=1' \
        'session.cookie_samesite=Lax' \
        'opcache.enable=1' \
        'opcache.memory_consumption=128' \
        'opcache.interned_strings_buffer=16' \
        'opcache.max_accelerated_files=10000' \
        'opcache.validate_timestamps=0' \
        'realpath_cache_size=4096K' \
        'realpath_cache_ttl=600' \
        > /usr/local/etc/php/conf.d/inventa-uploads.ini

RUN a2enmod rewrite headers

RUN printf '%s\n' \
    'ServerTokens Prod' \
    'ServerSignature Off' \
    '<Directory /var/www/html/>' \
    '    AllowOverride All' \
    '    Require all granted' \
    '</Directory>' \
    > /etc/apache2/conf-available/inventa.conf \
    && a2enconf inventa

EXPOSE 80
