# Base image for the PHP and Apache environment
FROM php:8.3-apache
# FROM php:apache  # Pull the latest Apache version

# Set the working directory for Apache
WORKDIR /var/www/html

# Update package lists and install required libraries for system utilities
RUN apt update -y && \
    apt install -y libicu-dev unzip zip curl ca-certificates build-essential software-properties-common gnupg && \
    apt clean && \
    update-ca-certificates

# Install Git, Node.js, NPM, and PNPM from NodeSource for the latest versions
RUN curl -fsSL https://deb.nodesource.com/setup_18.x | bash - && \
	apt update -y && \
	apt install -y git && \
	apt install -y nodejs && \
	npm install -g pnpm

# Configure PNPM to use a centralized store directory inside the container
RUN pnpm config set store-dir /root/.pnpm-store

# Install PHP extensions for database and internationalization support
RUN docker-php-ext-install gettext intl pdo_mysql mysqli && \
    docker-php-ext-enable mysqli

# Copy Composer from its latest version image
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer

# Add Sass to the environment path for easy access
ENV PATH=$PATH:/usr/local/dart-sass

# Enable Apache's `mod_rewrite` module for URL rewriting
RUN a2enmod rewrite

# Install Sass for CSS preprocessing
WORKDIR /usr/local
ARG SASS_VERSION=1.81.1
ARG SASS_URL="https://github.com/sass/dart-sass/releases/download/${SASS_VERSION}/dart-sass-${SASS_VERSION}-linux-x64.tar.gz"
RUN curl -OL $SASS_URL && \
    tar -xzf dart-sass-${SASS_VERSION}-linux-x64.tar.gz && \
    rm -rf dart-sass-${SASS_VERSION}-linux-x64.tar.gz

# Reset the working directory back to the default
WORKDIR /var/www/html
