FROM php:7.4.33-fpm-alpine3.15
RUN apk update
RUN docker-php-ext-install opcache
RUN docker-php-ext-install mysqli
RUN docker-php-ext-install pdo pdo_mysql

RUN apk add --no-cache libzip-dev && \
    docker-php-ext-install zip

# xdebug with VSCODE
ENV XDEBUG_VERSION=2.9.2
RUN apk --no-cache add --virtual .build-deps \
    g++ \
    autoconf \
    make && \
    pecl install xdebug-${XDEBUG_VERSION} && \
    docker-php-ext-enable xdebug && \
    apk del .build-deps && \
    rm -r /tmp/pear/* && \
    echo -e "xdebug.remote_enable=1\n\
    xdebug.remote_autostart=1\n\
    xdebug.remote_connect_back=0\n\
    xdebug.remote_port=9001\n\
    xdebug.idekey=\"VSCODE\"\n\
    xdebug.remote_host=host.docker.internal" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
# Instalar herramientas básicas como chmod
RUN apk add --no-cache coreutils
#COPY ../../../files/ /var/www
# Opcional: Crear carpetas con permisos específicos


# Configurar PHP para permitir ejecución prolongada
RUN echo "max_execution_time = 0" >> /usr/local/etc/php/conf.d/99-custom.ini
RUN echo "max_input_time = 0" >> /usr/local/etc/php/conf.d/99-custom.ini
RUN echo "memory_limit = 3G" >> /usr/local/etc/php/conf.d/99-custom.ini
RUN echo "post_max_size = 2G" >> /usr/local/etc/php/conf.d/99-custom.ini
RUN echo "upload_max_filesize = 1G" >> /usr/local/etc/php/conf.d/99-custom.ini

EXPOSE 9000

# 5. composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer


# Copiar todo el contenido desde la raíz del contexto al contenedor
COPY ./html /var/www/html

# Cambiar permisos de la carpeta de logs y otras necesarias
RUN chown -R www-data:www-data /var/www/html/application/logs && \
    chown -R www-data:www-data /var/www/html/uploads && \
    chmod -R 775 /var/www/html/application/logs && \
    chmod -R 775 /var/www/html/DOWNLOADS && \
    chmod -R 777 /var/www/html/uploads


WORKDIR /var/www/html


