# Utiliser l'image officielle de PHP avec Apache
FROM php:8.1-apache

# Installer les extensions PHP nécessaires
RUN apt-get update && apt-get install -y \
    git \
    unzip \
    libpq-dev \
    && docker-php-ext-install pdo pdo_mysql \
    && apt-get clean

COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
# Copier le contenu de votre projet dans le répertoire par défaut d'Apache
COPY ./ /var/www/

# Copier le fichier de configuration du Virtual Host
COPY ./config/vhosts.conf /etc/apache2/sites-available/httpd.conf
#RUN echo "Include /usr/local/apache2/conf/vhosts/*.conf" >> /usr/local/apache2/conf/httpd.conf
#RUN sed -i '$ a Include /usr/local/apache2/conf/vhosts/*.conf' /usr/local/apache2/conf/httpd.conf

# Changer les permissions si nécessaire
RUN chown -R www-data:www-data /var/www/service_5questions
RUN chown -R www-data:www-data /var/www/service_5questions/public/index.php && \
    chmod 644 /var/www/service_5questions/public/index.php

COPY ./config/vhosts.conf /etc/apache2/sites-available/000-default.conf

RUN chown -R www-data:www-data /var/www/service_5questions/public/.htaccess && \
    chmod 644 /var/www/service_5questions/public/.htaccess
# Activer le module rewrite d'Apache
#RUN a2enmod rewrite

# Définir le DocumentRoot pour Apache
#ENV APACHE_DOCUMENT_ROOT /var/www/html/project/public

# Mettre à jour la configuration d'Apache pour le DocumentRoot
#RUN echo "DocumentRoot ${APACHE_DOCUMENT_ROOT}" >> /etc/apache2/sites-available/000-default.conf

# Exposer le port 80
#EXPOSE 80
#RUN chown -R www-data:www-data /var/www/project/public
RUN a2enmod rewrite
WORKDIR /var/www/

EXPOSE 80

