# Base image
FROM php:7.4-apache

# Install system dependencies and enable PHP extensions
RUN apt-get update && \
    apt-get install -y libpng-dev libjpeg-dev libfreetype6-dev zip unzip && \
    docker-php-ext-configure gd --with-freetype --with-jpeg && \
    docker-php-ext-install gd && \
    docker-php-ext-install mysqli && \
    docker-php-ext-enable mysqli

# Enable Apache mod_rewrite
RUN a2enmod rewrite

# Copy application source code to /var/www/html/
COPY . /var/www/html/

# Set working directory
WORKDIR /var/www/html

# Expose port 80 for the web server
EXPOSE 80

# Set up MySQL environment variables
ENV MYSQL_ROOT_PASSWORD=Mr#1449391
ENV MYSQL_DATABASE=betcopoll
ENV MYSQL_USER=ayrik
ENV MYSQL_PASSWORD=Mr#1449391

# Add entrypoint script to initialize the MySQL database
COPY docker-entrypoint.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/docker-entrypoint.sh

ENTRYPOINT ["docker-entrypoint.sh"]

CMD ["apache2-foreground"]

