FROM php:8.3-apache

RUN set -eux; \
    apt-get update; \
    apt-get install -y --no-install-recommends libsqlite3-dev libonig-dev; \
    docker-php-ext-install pdo_sqlite mbstring; \
    a2enmod rewrite headers remoteip; \
    apt-get clean; \
    rm -rf /var/lib/apt/lists/*

RUN sed -ri 's!AllowOverride None!AllowOverride All!g' /etc/apache2/apache2.conf

RUN set -eux; \
    { \
      echo 'RemoteIPHeader X-Forwarded-For'; \
      echo 'RemoteIPTrustedProxy 10.0.0.0/8'; \
      echo 'RemoteIPTrustedProxy 172.16.0.0/12'; \
      echo 'RemoteIPTrustedProxy 192.168.0.0/16'; \
    } > /etc/apache2/conf-available/remoteip.conf; \
    a2enconf remoteip

COPY docker-entrypoint.sh /usr/local/bin/contactbox-entrypoint
RUN chmod +x /usr/local/bin/contactbox-entrypoint

COPY . /var/www/html/
RUN set -eux; \
    rm -f /var/www/html/docker-entrypoint.sh; \
    chown -R www-data:www-data /var/www/html

ENTRYPOINT ["contactbox-entrypoint"]
CMD ["apache2-foreground"]
