FROM php:7.4-apache

# Install dependencies for PHP extensions
RUN apt-get update && apt-get install -y \
        libpng-dev \
        libjpeg-dev \
        libfreetype6-dev \
        libwebp-dev \
        libxpm-dev \
        pkg-config \
        libonig-dev \
        libxml2-dev \
        libgmp-dev \
        libsodium-dev \
        unzip \
        git \
        zlib1g-dev \
    && rm -rf /var/lib/apt/lists/*

# Configure GD
RUN docker-php-ext-configure gd --with-freetype --with-jpeg

# Install PHP extensions + composer
RUN docker-php-ext-install gd mysqli opcache soap sodium gmp mbstring pdo_mysql
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

# Set working directory
WORKDIR /var/www/html

# Copy project files
COPY application/composer.json ./
COPY php.ini /usr/local/etc/php/conf.d/custom.ini
COPY . .

# Cleaning up + permissions
RUN rm -rf screenshots
RUN chown -R www-data:www-data /var/www/html \
    && chmod -R 755 /var/www/html

# Install PHP dependencies
RUN composer install --no-dev --optimize-autoloader

# Expose Apache port
EXPOSE 80
