FROM php:7.4-fpm

# Установка системных зависимостей по частям для кэшируемости и отладки
RUN apt-get update && apt-get install -y --no-install-recommends \
    build-essential autoconf gcc make

RUN apt-get install -y --no-install-recommends \
    libfreetype6-dev libjpeg62-turbo-dev libpng-dev libwebp-dev libxpm-dev

RUN apt-get install -y --no-install-recommends \
    libonig-dev libxml2-dev libzip-dev zlib1g-dev

RUN apt-get install -y --no-install-recommends \
    libicu-dev libxslt1-dev

RUN apt-get install -y --no-install-recommends \
    libmemcached-dev libmagickwand-dev libpspell-dev libsnmp-dev

RUN apt-get install -y --no-install-recommends \
    libreadline-dev libfann-dev libgeoip-dev libgearman-dev

RUN apt-get install -y --no-install-recommends \
    unzip zip cron supervisor

# Настройка GD
RUN docker-php-ext-configure gd \
    --with-freetype \
    --with-jpeg \
    --with-webp \
    --with-xpm


# Установка PHP-расширений по частям
RUN docker-php-ext-install -j$(nproc) bcmath calendar exif gettext gd
RUN docker-php-ext-install -j$(nproc) intl mbstring mysqli opcache pcntl
RUN docker-php-ext-install -j$(nproc) pdo pdo_mysql posix shmop
RUN docker-php-ext-install -j$(nproc) snmp soap sockets sysvmsg sysvsem sysvshm
RUN docker-php-ext-install -j$(nproc) xsl zip

RUN apt-get update && apt-get install -y libsodium-dev \
    && docker-php-ext-install sodium


# Очистка
RUN apt-get clean && rm -rf /var/lib/apt/lists/*

# Установка PECL-расширений
RUN pecl install memcached-3.2.0 && docker-php-ext-enable memcached
RUN pecl install gearman-2.1.0 && docker-php-ext-enable gearman
RUN pecl install imagick-3.7.0 && docker-php-ext-enable imagick
RUN pecl install igbinary-3.2.14 && docker-php-ext-enable igbinary
RUN pecl install msgpack-2.1.2 && docker-php-ext-enable msgpack
RUN pecl install geoip-1.1.1 && docker-php-ext-enable geoip
RUN pecl install fann-1.1.1 && docker-php-ext-enable fann

RUN ln -sf /usr/share/zoneinfo/Europe/Moscow /etc/localtime && echo "Europe/Moscow" > /etc/timezone


# Установка composer
COPY --from=composer:2 /usr/bin/composer /usr/bin/composer

# Общий конфиг
COPY ./config/php/php.ini /usr/local/etc/php/
COPY ./config/php/www.conf /usr/local/etc/php-fpm.d/www.conf

# Рабочая директория
WORKDIR /var/www/html
