FROM php:8.3-fpm-alpine

# 安装系统依赖 + PHP 扩展 + Nginx
RUN apk add --no-cache \
        $PHPIZE_DEPS \
        nginx \
        libjpeg-turbo-dev \
        libpng-dev \
        freetype-dev \
        curl-dev \
        libzip-dev \
        zip \
        unzip \
    # 配置 gd 扩展
    && docker-php-ext-configure gd \
        --with-jpeg \
        --with-freetype \
    # 安装 PHP 官方扩展
    && docker-php-ext-install -j$(nproc) \
        gd \
        curl \
        pdo_mysql \
        zip \
    # 安装 Redis 扩展（来自 PECL）
    && pecl install redis \
    && docker-php-ext-enable redis \
    # 清理构建依赖
    && apk del --no-cache $PHPIZE_DEPS \
    && rm -rf /tmp/pear

# 固定主配置，保证 include conf.d 并有默认兜底站点
COPY nginx/nginx.conf /etc/nginx/nginx.conf

# 默认配置文件 → 备用目录
COPY nginx/default-app/ /opt/default-app/

RUN chown -R nginx:nginx /opt/default-app

COPY start.sh /start.sh
RUN chmod +x /start.sh

EXPOSE 80

CMD ["/start.sh"]