# 使用基于 CentOS 6.8 的官方镜像
FROM centos:6.8
#添加用户
RUN useradd -M -s /sbin/nologin www
#备份yum源
RUN mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
#设置yum源
COPY CentOS-Base.repo /etc/yum.repos.d/
# 定义环境变量
ENV PHP_VERSION 5.6.40
# 安装基本依赖
RUN yum -y update && \
yum -y install epel-release && \
yum -y install \
gcc \
gcc-c++ \
make \
zlib-devel \
libxml2-devel \
openssl-devel \
curl-devel \
libjpeg-turbo-devel \
libpng-devel \
freetype-devel \
libmcrypt-devel \
libxslt-devel \
libtool \
autoconf \
wget \
libicu \
libicu-devel \
libc-client-devel \
readline-devel \
unzip
# 下载并解压 PHP 源文件
ADD php/php-${PHP_VERSION}.tar.gz /tmp/php
# 编译安装 PHP
RUN cd /tmp/php/php-${PHP_VERSION} && \
./configure \
--prefix=/usr/local/php \
--with-config-file-path=/usr/local/php/etc \
--enable-fpm \
--with-fpm-user=www \
--with-fpm-group=www \
--enable-mbstring \
--enable-mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-mysql=mysqlnd \
--with-curl \
--with-openssl \
--with-zlib \
--with-gd \
--with-jpeg-dir \
--with-png-dir \
--with-freetype-dir \
--with-mcrypt \
--with-xmlrpc \
--with-xsl \
--with-pear \
--with-pcre-regex \
--with-gettext \
--with-iconv \
--with-mhash \
--with-openssl \
--with-readline \
--without-sqlite3 \
-without-pdo-sqlite \
--enable-maintainer-zts \
--with-kerberos \
--enable-soap \
--enable-pcntl \
--enable-bcmath \
--enable-mbregex \
--enable-gd-native-ttf \
--enable-intl \
--enable-soap \
--enable-session \
--enable-pcntl \
--enable-xml \
--enable-inline-optimization \
--enable-shared\
--enable-zip && \
make && make install
# 复制 PHP 配置文件
RUN cp /tmp/php/php-${PHP_VERSION}/php.ini-production /usr/local/php/etc/php.ini
# 配置 PHP-FPM
COPY php-fpm.conf /usr/local/php/etc/php-fpm.conf
# 清理安装过程中的临时文件
RUN rm -rf /tmp/php
#暴露端口
EXPOSE 9000
CMD ["/usr/local/php/sbin/php-fpm", "-F", "-y", "/usr/local/php/etc/php-fpm.conf"]