ARG PHP_VERSION=php:5.6.36-fpm-alpine3.4
FROM ${PHP_VERSION}

ARG TZ=Asia/Shanghai
ARG PHP_EXTENSIONS=pdo_mysql,mysqli,mbstring,gd,curl,opcache,yaf,bcmath,mbstring,gettext,yaml,mongo,rar,redis,phalcon
ARG CONTAINER_PACKAGE_URL=mirrors.163.com


# RUN sed -i "s/dl-cdn.alpinelinux.org/${CONTAINER_PACKAGE_URL}/g" /etc/apk/repositories


COPY ./extensions /tmp/extensions
WORKDIR /tmp/extensions
RUN chmod +x install.sh \
    && sh install.sh \
    && rm -fr /tmp/extensions


RUN apt-get install tzdata \
    && cp "/usr/share/zoneinfo/$TZ" /etc/localtime \
    && echo "$TZ" > /etc/timezone


# Debian/Ubuntu 上有内置的iconv，不需要这个了
# Fix: https://github.com/docker-library/php/issues/240
# RUN apt-get update && apt-get install gnu-libiconv
#RUN apk add gnu-libiconv=1.15-r3 --update-cache --repository http://dl-cdn.alpinelinux.org/alpine/v3.10/community/ --allow-untrusted
# ENV LD_PRELOAD /usr/lib/preloadable_libiconv.so php


# php image's www-data user uid & gid are 82, change them to 1000 (primary user)
RUN usermod -u 1000 www-data && groupmod -g 1000 www-data

RUN chown www-data:www-data /usr/local/etc/php/conf.d

RUN command touch /xdebug_configured

RUN chown www-data:www-data /xdebug_configured

# Use www-data to run the first process
USER www-data


WORKDIR /www
