FROM php:apache

# Install necessary PHP extensions and tools
RUN apt-get update && \
    apt-get install -y libzip-dev zip zlib1g-dev git unzip && \
    docker-php-ext-install mysqli zip && \
    pecl install redis && \
    docker-php-ext-enable redis

# Enable Apache modules
RUN a2enmod ssl headers

# Restart Apache to apply changes
RUN service apache2 restart

# Set working directory
WORKDIR /var/www/html

# Copy application code
COPY ./app-code /var/www/html

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

RUN mkdir -p /var/www/vendor
RUN chown -R www-data:www-data /var/www/vendor
# Install WebAuthn library using Composer
RUN composer require web-auth/webauthn-lib --working-dir=/var/www/vendor
RUN composer require web-auth/webauthn-framework --working-dir=/var/www/vendor


# Create necessary directories with appropriate permissions
RUN mkdir -p /var/www/html/install/ \
    /var/www/html/database_srv \
    /var/www/html/export \
    /var/www/html/import && \
    chown -R www-data:www-data /var/www/html/export/ \
    /var/www/html/import/ \
    /var/www/html/install/ \
    /var/www/html/database_srv/
