FROM php:8.3-fpm

ARG XDEBUG_VERSION="xdebug-3.4.0"
ARG UID=1000
ARG GID=1000

# Install dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
    htop \
    wget \
    lynx \
    curl \
    mc \
    vim \
    libmcrypt-dev \
    libicu-dev \
    libfreetype6-dev \
    libjpeg-dev \
    libpng-dev \
    libxml2-dev \
    unzip \
    libzip-dev \
    locales \
    tzdata \
    nano

RUN docker-php-ext-install mysqli \
    && docker-php-ext-install pdo_mysql

RUN docker-php-ext-install gd \
    && docker-php-ext-configure gd \
    &&  docker-php-ext-enable gd

RUN docker-php-ext-install zip \
    && docker-php-ext-configure zip \
    &&  docker-php-ext-enable zip

RUN yes | pecl install ${XDEBUG_VERSION}

RUN curl --insecure 'https://pecl.php.net/get/redis-5.3.7.tgz' -o redis-5.3.7.tgz \
    && pecl install --offline redis-5.3.7.tgz \
    && rm -rf redis-5.3.7.tgz \
    && rm -rf /tmp/pear \
    && docker-php-ext-enable redis

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

# create dir "files" for symlink
RUN mkdir /var/files && \
    chown ${UID}:${GID} /var/files && \
    chown ${UID}:${GID} -R /var/www

# Set working directory
WORKDIR /var/www/

# cleanup
RUN apt-get clean \
    && rm -fr /var/lib/apt/lists/* \
    && rm -fr /tmp/* \
    && rm -fr /var/tmp/*

#
RUN usermod -u ${UID} www-data

USER ${UID}
