Dockerfile 中 配置安装 php 扩展

添加redis扩展

源码安装方式

ARG INSTALL_PHPREDIS=true
ARG PHPREDIS_VERSION=3.1.3
RUN if [ ${INSTALL_PHPREDIS} = true ]; then \
# Install Php Redis Extension
curl -L -o /tmp/redis.tar.gz https://github.com/phpredis/phpredis/archive/${PHPREDIS_VERSION}.tar.gz \
&& tar xfz /tmp/redis.tar.gz \
&& rm -r /tmp/redis.tar.gz \
&& mkdir -p /usr/src/php/ext \
&& mv phpredis-${PHPREDIS_VERSION} /usr/src/php/ext/redis \
&& docker-php-ext-install redis \
&& rm -rf /usr/src/php \
;fi

PECL安装方式

ARG INSTALL_PHPREDIS=false
RUN if [ ${INSTALL_PHPREDIS} = true ]; then \
# Install Php Redis Extension
printf "\n" | pecl install -o -f redis \
&& rm -rf /tmp/pear \
&& docker-php-ext-enable redis \
;fi

注:

源码安装方式的可以选择版本,PECL安装的记得注意php版本,因为默认会安装最新的版本

swoole扩展安装

#####################################
# Swoole EXTENSION FOR PHP 5
#####################################
ARG INSTALL_SWOOLE=false
ARG PHPSWOOLE_VERSION=1.9.23
RUN if [ ${INSTALL_SWOOLE} = true ]; then \
# Install Php Redis Extension
curl -L -o /tmp/swoole.tar https://pecl.php.net/get/swoole-${PHPSWOOLE_VERSION}.tar \
&& tar xvf /tmp/swoole.tar \
&& rm -r /tmp/swoole.tar \
&& mkdir -p /usr/src/php/ext \
&& mv swoole-${PHPSWOOLE_VERSION} /usr/src/php/ext/swoole \
&& docker-php-ext-install swoole \
&& rm -rf /usr/src/php \
;fi