FROM php:8.3-apache

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

# Enable Apache mod_rewrite
RUN a2enmod rewrite cgid

# Install Composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer

# Set working directory
WORKDIR /var/www/html

# Create Apache virtual host configuration
RUN echo 'NameVirtualHost *:80\n\
    \n\
    <VirtualHost *:80>\n\
    ServerName localhost\n\
    \n\
    # Carpeta raíz principal del sitio\n\
    DocumentRoot /var/www/html/appweb/public\n\
    \n\
    # Configuración para procesar archivos .slm como PHP\n\
    <FilesMatch "\.slm$">\n\
        SetHandler application/x-httpd-php\n\
    </FilesMatch>\n\
    \n\
    DirectoryIndex index.slm\n\
    \n\
    # Configuración para la carpeta pública principal\n\
    <Directory /var/www/html/appweb/public>\n\
        Options Indexes FollowSymLinks\n\
        AllowOverride All\n\
        Require all granted\n\
        DirectoryIndex index.slm\n\
    </Directory>\n\
    \n\
    # Archivos de log para depuración del servidor web\n\
    ErrorLog ${APACHE_LOG_DIR}/error.log\n\
    CustomLog ${APACHE_LOG_DIR}/access.log combined\n\
</VirtualHost>' > /etc/apache2/sites-available/000-slm-framework-skeleton.conf

RUN a2ensite 000-slm-framework-skeleton.conf
RUN a2dissite 000-default.conf

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

EXPOSE 80

CMD ["apache2-foreground"]
