# Use the official PHP 7.4 image as the base image
FROM php:7.4-apache

# Install necessary system packages and PHP extensions
RUN apt-get update && apt-get install -y \
    libfreetype6-dev \
    libjpeg62-turbo-dev \
    libpng-dev \
    libwebp-dev \
    libzip-dev \
    libmagickwand-dev \
    zlib1g-dev \
    libmemcached-dev \
    libssl-dev \
    pkg-config \
    zip \
    unzip \
    git \
    curl \
    && docker-php-ext-configure gd --with-freetype --with-jpeg --with-webp \
    && docker-php-ext-install -j$(nproc) gd \
    && docker-php-ext-install zip \
    && docker-php-ext-install pdo_mysql \
    && pecl install redis \
    && pecl install mongodb \
    && pecl install imagick \
    && docker-php-ext-enable redis \
    && docker-php-ext-enable mongodb \
    && docker-php-ext-enable imagick \
    && a2enmod rewrite

# Set up the working directory
WORKDIR /var/www/html

# Copy the application code to the working directory
COPY . /var/www/html

# Set appropriate permissions
RUN chown -R www-data:www-data /var/www/html

# Copy the Apache configuration file
COPY ./docker/apache.conf /etc/apache2/sites-available/000-default.conf

# Expose port 80
EXPOSE 80

# Start Apache server
CMD ["apache2-foreground"]
