FROM php:8.3-apache

# Install dependencies
RUN apt-get update && apt-get install -y \
    libzip-dev \
    zip \
    unzip \
    && docker-php-ext-install zip

# Install PHP extensions
RUN docker-php-ext-install pdo pdo_mysql

# Enable Apache modules
RUN a2enmod rewrite

# Configure PHP to hide warnings and errors
# Create directory for PHP logs
RUN mkdir -p /var/log/php && chown www-data:www-data /var/log/php

# Copy custom php.ini file
COPY php.ini /usr/local/etc/php/php.ini

# Set working directory
WORKDIR /var/www/html

RUN chown www-data:www-data . -R

# Copy connect.php.docker to connect.php when container starts
COPY /Functions/DatabaseSettings.php.docker /Functions/DatabaseSettings.php

# Apache configuration
RUN echo "ServerName localhost" >> /etc/apache2/apache2.conf

# Copy custom Apache configuration
COPY townofamity.conf /etc/apache2/sites-available/
RUN a2dissite 000-default.conf && a2ensite townofamity.conf

# Expose port 80
EXPOSE 80

# Start Apache
CMD ["apache2-foreground"]
