FROM php:8.4-apache


RUN apt-get update && apt-get install -y \
    gnupg2 \
    libzip-dev \
    zlib1g-dev \
    libpng-dev \
    libfreetype6-dev \
    libjpeg62-turbo-dev \
    libmcrypt-dev \
    libxml2-dev \
    libicu-dev \
    libpq-dev \
    && docker-php-ext-configure gd --with-freetype --with-jpeg \
    && docker-php-ext-install -j$(nproc) zip pdo exif pdo_pgsql gd intl \
    && docker-php-ext-enable exif \
    && rm -rf /var/lib/apt/lists/*

# Enable Apache modules
RUN a2enmod rewrite

# Align www-data UID for permission consistency with host (optional but common)
RUN usermod -u 1000 www-data

# Install Composer using the official image (faster/cleaner than curl)
COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer
# Configure Apache Document Root
ENV APACHE_DOCUMENT_ROOT /var/www/html/public
RUN sed -ri -e 's!/var/www/html!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/sites-available/*.conf \
    && sed -ri -e 's!/var/www/!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf

WORKDIR /var/www/html