FROM php:8.5-apache

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

# Xdebug
RUN pecl install xdebug \
  && docker-php-ext-enable xdebug

# Apache modules
RUN a2enmod rewrite

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

# Install git & unzip (needed by Composer for some packages)
RUN apt-get update && apt-get install -y --no-install-recommends \
    git unzip \
  && rm -rf /var/lib/apt/lists/*

# Copy composer files first for better Docker layer caching
COPY composer.json composer.lock /var/www/html/

# Install PHP dependencies (no dev, optimised autoloader)
RUN composer install --no-dev --optimize-autoloader --no-interaction --working-dir=/var/www/html

# Vhost
COPY php/apache-vhost.conf /etc/apache2/sites-available/000-default.conf
