FROM php:8.2-apache

RUN apt-get -y update && apt-get -y install zlib1g-dev libpng-dev
ADD https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/

RUN chmod +x /usr/local/bin/install-php-extensions && \
    install-php-extensions gd mysqli

# Cleanup
RUN apt-get clean && \
    rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/*

ENV APACHE_DOCUMENT_ROOT /var/www
ENV APACHE_RUN_USER www-data

RUN sed -ri -e 's!/var/www/html!/var/www/public!g' /etc/apache2/sites-available/*.conf
RUN sed -ri -e 's!/var/www/!/var/www/public!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf
RUN sed -ri -e 's!AllowOverride None!AllowOverride All!g' /etc/apache2/apache2.conf

RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"
RUN sed -ri -e 's!upload_max_filesize = 2M!upload_max_filesize = 8M!g' $PHP_INI_DIR/php.ini

RUN a2enmod rewrite

ARG UNAME=www-data
ARG UGROUP=www-data
ARG UID=1000
ARG GID=1000

RUN usermod --uid $UID $UNAME
RUN groupmod --gid $GID $UGROUP

WORKDIR ${APACHE_DOCUMENT_ROOT}

COPY . ${APACHE_DOCUMENT_ROOT}

VOLUME ${APACHE_DOCUMENT_ROOT}
