# FROM php:7.4-fpm

# # Copy composer.lock and composer.json into the working directory
# COPY composer.lock composer.json /var/www/html/

# # Set working directory
# WORKDIR /var/www/html/

# # Install dependencies for the operating system software
# RUN apt-get update && apt-get install -y \
#   build-essential \
#   libpng-dev \
#   libjpeg62-turbo-dev \
#   libfreetype6-dev \
#   locales \
#   zip \
#   jpegoptim optipng pngquant gifsicle \
#   vim \
#   libzip-dev \
#   unzip \
#   git \
#   libonig-dev \
#   curl

# # Clear cache
# RUN apt-get clean && rm -rf /var/lib/apt/lists/*

# # Install extensions for php
# RUN docker-php-ext-install pdo_mysql mbstring zip exif pcntl
# RUN docker-php-ext-configure gd --with-freetype --with-jpeg
# RUN docker-php-ext-install gd

# # Install composer (php package manager)
# RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

# # Copy existing application directory contents to the working directory
# COPY . /var/www/html

# # Assign permissions of the working directory to the www-data user
# RUN chown -R www-data:www-data \
#   /var/www/html/storage \
#   /var/www/html/bootstrap/cache

# # Expose port 9000 and start php-fpm server (for FastCGI Process Manager)
# EXPOSE 9000
# CMD ["php-fpm"]

# Use an official PHP image as the base image
FROM php:7.4-apache

# Set the working directory in the container (e.g., for your Laravel application)
WORKDIR /var/www/html

# Install system dependencies and extensions required for Laravel
RUN apt-get update && \
  apt-get install -y libpng-dev libjpeg-dev libfreetype6-dev zip unzip && \
  docker-php-ext-configure gd --with-freetype --with-jpeg && \
  docker-php-ext-install gd pdo pdo_mysql

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

# Copy the Laravel application files into the container
COPY . /var/www/html

# Install Laravel dependencies using Composer
RUN composer install --no-scripts

# Set the necessary file permissions (adjust as needed)
RUN chown -R www-data:www-data /var/www/html/storage /var/www/html/bootstrap/cache

# Expose the web server port (default is 80)
EXPOSE 80

# Start the Apache web server
CMD ["apache2-foreground"]
