FROM php:8.2.0-apache-bullseye

LABEL maintainer="supports.maintenances@ngser.com"

RUN apt-get update && apt-get install -y \
    git zip libpq-dev libzip-dev nano vim libxcb1 \
    build-essential libgl1-mesa-dev qtbase5-dev qtchooser libxcb1 libxcb1-dev \
    libpng-dev libjpeg-dev libfreetype6-dev \
    libapache2-mod-security2

RUN docker-php-ext-install gd mysqli pdo_mysql pdo zip && \
    docker-php-ext-configure gd --with-jpeg --with-freetype && \
    docker-php-ext-install gd

RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

# Install node and npm
RUN curl -sL https://deb.nodesource.com/setup_18.x | bash - && \
    apt-get update && apt install -y nodejs 

# Activer Apache Modules
RUN a2enmod rewrite headers security2
RUN a2enmod proxy
RUN a2enmod proxy_http
RUN a2enmod proxy_balancer
RUN a2enmod lbmethod_byrequests

# Configurer ModSecurity
RUN cp /etc/modsecurity/modsecurity.conf-recommended /etc/modsecurity/modsecurity.conf && \
    sed -i 's/SecRuleEngine DetectionOnly/SecRuleEngine On/' /etc/modsecurity/modsecurity.conf

# Redémarrer Apache
RUN service apache2 restart

# Définir le répertoire de travail
WORKDIR /var/www/html
RUN pwd
# Configurer les permissions
RUN mkdir -p /var/www/html

# Copier le projet dans le conteneur
COPY . /var/www/html/

# Appliquer les permissions
RUN chmod -R 755 /var/www/html && chown -R www-data:www-data /var/www/html

# Vérifier la version de Git et Apache
RUN git config --global --add safe.directory /var/www/html
RUN apache2 -v
