# Use build argument to easily change PHP version
ARG PHP_VERSION=8.3
FROM php:${PHP_VERSION}-apache

WORKDIR /var/www/html

# Install PHP extensions & tools
RUN apt-get update && apt-get install -y \
    libpng-dev libonig-dev libxml2-dev zip unzip git curl default-mysql-client \
    && docker-php-ext-install pdo_mysql mbstring exif pcntl bcmath gd \
    && a2enmod rewrite

# Add Node.js and npm to the image using the official Node.js package
RUN curl -fsSL https://deb.nodesource.com/setup_lts.x | bash - \
    && apt-get install -y nodejs


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

# Copy entrypoint
COPY docker/docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
RUN chmod +x /usr/local/bin/docker-entrypoint.sh

ENTRYPOINT ["docker-entrypoint.sh"]

# Copy a custom Apache virtual host for Laravel
COPY docker/000-default.conf /etc/apache2/sites-available/000-default.conf

# Enable mod_rewrite
RUN a2enmod rewrite

# Expose Apache port
EXPOSE 80
