FROM php:8.2-apache

# Install system dependencies + PHP extensions
RUN apt-get update && apt-get install -y \
    git curl unzip libpng-dev libonig-dev libxml2-dev libpq-dev sudo libzip-dev zip unzip postgresql-client \
    && docker-php-ext-install pdo_pgsql mbstring exif pcntl bcmath gd zip

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

# Enable Apache rewrite
RUN a2enmod rewrite

# Set working directory
WORKDIR /var/www/html

# Copy project files
COPY .. .

# Install PHP dependencies (with optimized autoloader)
RUN composer install --no-dev --optimize-autoloader --no-interaction --prefer-dist || true

# Apache config
COPY vhost.conf /etc/apache2/sites-available/000-default.conf

# Entrypoint
CMD ["/var/www/html/docker/php-apache/entrypoint.sh"]
