# FROM php:5.6.38-apache-stretch
FROM php:7.2.5-apache-stretch

ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && \
    apt-get -y install \
        gnupg2 && \
    apt-key update && \
    apt-get update && \
    apt-get -y install \
            g++ \
            git \
            curl \
            imagemagick \
            libfreetype6-dev \
            libcurl3-dev \
            libicu-dev \
            libfreetype6-dev \
            libjpeg-dev \
            libjpeg62-turbo-dev \
            libmagickwand-dev \
            libpq-dev \
            libpng-dev \
            libxml2-dev \
            zlib1g-dev \
            mysql-client \
            openssh-client \
            nano \
            unzip \
        --no-install-recommends && \
        apt-get clean && \
        rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

# Install PHP extensions required for Yii 2.0 Framework
RUN docker-php-ext-configure gd \
        --with-freetype-dir=/usr/include/ \
        --with-png-dir=/usr/include/ \
        --with-jpeg-dir=/usr/include/ && \
    docker-php-ext-configure bcmath && \
    docker-php-ext-install \
        soap \
        zip \
        curl \
        bcmath \
        exif \
        gd \
        iconv \
        intl \
        mbstring \
        opcache \
        pdo_mysql \
        pdo_pgsql

# Install PECL extensions
# see http://stackoverflow.com/a/8154466/291573) for usage of `printf`
RUN printf "\n" | pecl install \
        imagick && \
    docker-php-ext-enable \
        imagick

# RUN printf "\n" | pecl install \
#         xdebug && \
#     docker-php-ext-enable \
#         xdebug

# Environment settings
ENV PHP_USER_ID=33 \
    PHP_ENABLE_XDEBUG=1 \
    PATH=/app:/app/vendor/bin:/root/.composer/vendor/bin:$PATH \
    TERM=linux \
    VERSION_PRESTISSIMO_PLUGIN=^0.3.7 \
    COMPOSER_ALLOW_SUPERUSER=1 \
    DOCKER_FOR_MAC_LOCALHOST=1

# Add configuration files
# COPY image-files/ /
COPY vhosts.conf /etc/apache2/sites-enabled/

# Add GITHUB_API_TOKEN support for composer
# RUN chmod 700 \
#         /usr/local/bin/docker-php-entrypoint \
#         /usr/local/bin/composer

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

# Install composer plugins
# RUN composer global require --optimize-autoloader \
#         "hirak/prestissimo:${VERSION_PRESTISSIMO_PLUGIN}" && \
#     composer global dumpautoload --optimize && \
#     composer global require "fxp/composer-asset-plugin:^1.4.2" && \
#     composer clear-cache

# Application environment
# CMD composer install && a2enmod rewrite && apache2-foreground
RUN a2enmod rewrite
COPY xdebug.ini /usr/local/etc/php/conf.d/

