FROM php:8.1.11-fpm

# basic
RUN sed -i 's/deb.debian.org/mirrors.aliyun.com/g' /etc/apt/sources.list \
    && sed -i 's/security.debian.org/mirrors.aliyun.com/g' /etc/apt/sources.list \
    && apt-get update -y \
    && apt-get upgrade -y \
    && apt-get install wait-for-it --no-install-recommends -y

# `exif extension`
RUN docker-php-ext-configure exif \
    && docker-php-ext-install -j $(nproc) exif

# `zip extension`
RUN apt-get install -y --no-install-recommends libzip-dev \
    && docker-php-ext-configure zip \
    && docker-php-ext-install -j $(nproc) zip

# `bcmath extension`
RUN docker-php-ext-configure bcmath \
    && docker-php-ext-install -j $(nproc) bcmath

# `pdo_mysql extension`
RUN docker-php-ext-configure pdo_mysql \
    && docker-php-ext-install -j $(nproc) pdo_mysql

# `mysqli extension`
RUN docker-php-ext-configure mysqli \
    && docker-php-ext-install -j $(nproc) mysqli

# `redis extension`
RUN pecl install -o -f redis \
    && rm -rf /tmp/pear \
    && docker-php-ext-enable redis

# `composer`
RUN curl https://mirrors.aliyun.com/composer/composer.phar -o /bin/composer \
    && chmod +x /bin/composer

# `gd extension`
RUN apt-get install -y --no-install-recommends \
      libwebp-dev \
      libjpeg-dev \
      libpng-dev \
      libxpm-dev \
      libfreetype6-dev
RUN docker-php-ext-configure gd \
    	--enable-gd \
    	--with-webp \
    	--with-jpeg \
    	--with-xpm \
    	--with-freetype \
    && docker-php-ext-install -j $(nproc) gd

# `mysqli extension`
RUN docker-php-ext-configure sockets \
    && docker-php-ext-install -j $(nproc) sockets

# `opcache`
RUN docker-php-ext-configure opcache
COPY opcache.ini /usr/local/etc/php/conf.d/opcache.ini

# `php.ini`
COPY php.ini /usr/local/etc/php/php.ini

# `xdebug`
#RUN pecl install xdebug
#COPY debug.ini /usr/local/etc/php/conf.d/xdebug.ini

# `crontab`
# `echo "" >> /etc/crontab` 确保最后一行有一个空行, 否则可能无法执行
RUN apt-get install cron -y --no-install-recommends
COPY crontab /etc/crontab
RUN chown root:root /etc/crontab \
    && chmod 0644 /etc/crontab

# clean
RUN apt-get clean -y \
    && apt-get autoclean -y \
    && apt-get autoremove -y

COPY php-fpm.d/www.conf /usr/local/etc/php-fpm.d/www.conf
RUN chmod 777 /tmp -R
RUN mkdir /var/log/php-fpm && chown 33.33 /var/log/php-fpm -R
WORKDIR /var/www
