FROM php:8.2-apache

# Install required PHP extensions and dependencies
# RUN apt-get update && apt-get install -y \
#     unzip \
#     libicu-dev \
#     libonig-dev \
#     libzip-dev \
#     libxml2-dev \
#     libcurl4-openssl-dev \
#     libpng-dev \
#     libjpeg-dev \
#     libfreetype6-dev \
#     libkrb5-dev \
#     libc-client-dev \
#     && docker-php-ext-configure imap --with-kerberos --with-imap-ssl \
#     && docker-php-ext-install \
#     intl \
#     mbstring \
#     zip \
#     imap \
#     mysqli \
#     pdo_mysql \
#     gd \
#     && apt-get clean && rm -rf /var/lib/apt/lists/*



# Install required PHP extensions and dependencies
# RUN apt-get update && apt-get install -y \
#  wget \
#      && docker-php-ext-install \
#     mysqli \
#     pdo_mysql \
#     && apt-get clean && rm -rf /var/lib/apt/lists/*



RUN apt-get update && apt-get install -y \
    wget \
    # && docker-php-ext-configure imap --with-kerberos --with-imap-ssl \
    # && docker-php-ext-install imap  \
    # build-essential \
    # && docker-php-ext-configure imap \
    # && docker-php-ext-install imap mysqli pdo_mysql \
    && docker-php-ext-install mysqli pdo_mysql \
    && apt-get clean && rm -rf /var/lib/apt/lists/*


#     # Configure and install imap extension
# RUN docker-php-ext-configure imap --with-imap=/usr --with-kerberos --with-imap-ssl && \
#     docker-php-ext-install imap

# Install pecl manually
RUN wget https://pear.php.net/go-pear.phar && \
    php go-pear.phar && \
    rm go-pear.phar

    # apt-get install libc-client-dev -y
# apt-get install libkrb5-dev -y


# Install mailparse using pecl
RUN pecl install mailparse && docker-php-ext-enable mailparse 
    
# RUN pecl install imap && \
#     docker-php-ext-enable imap && \
#     pecl install mailparse && docker-php-ext-enable mailparse

# Enable Apache rewrite module
RUN a2enmod rewrite

# Set working directory
WORKDIR /var/www/html

# Copy the UVdesk zip file to the container
# Replace 'uvdesk.zip' with the actual name of your UVdesk zip file
COPY . /var/www/html/

# Set permissions for the application
RUN chown -R www-data:www-data /var/www/html && \
    chmod -R 775 /var/www/html/var /var/www/html/config /var/www/html/public /var/www/html/migrations /var/www/html/.env

# Expose port 80
EXPOSE 80

# Start Apache
CMD ["apache2-foreground"]