From d5ef6b4a1071e1bffbe56a6d310810758adc1993 Mon Sep 17 00:00:00 2001 From: yeszao Date: Mon, 7 Oct 2019 11:25:15 +0800 Subject: [PATCH] Use phpize to install tgz extensions instead of pecl --- services/php/Dockerfile | 2 +- services/php/extensions/install.sh | 79 +++++++++++++++++++----------- 2 files changed, 52 insertions(+), 29 deletions(-) diff --git a/services/php/Dockerfile b/services/php/Dockerfile index e9f14d95..4720f9a9 100644 --- a/services/php/Dockerfile +++ b/services/php/Dockerfile @@ -16,7 +16,7 @@ RUN if [ "${CONTAINER_PACKAGE_URL}" != "" ]; then \ RUN if [ "${PHP_EXTENSIONS}" != "" ]; then \ - apk add --no-cache autoconf g++ libtool make curl-dev libxml2-dev libevent-dev linux-headers; \ + apk add --no-cache autoconf g++ libtool make curl-dev linux-headers; \ fi diff --git a/services/php/extensions/install.sh b/services/php/extensions/install.sh index fb60c6b3..a0d38af0 100644 --- a/services/php/extensions/install.sh +++ b/services/php/extensions/install.sh @@ -17,6 +17,19 @@ echo export EXTENSIONS=",${PHP_EXTENSIONS}," +# +# Check if current php version is greater than or equal to +# specific version. +# +# For example, to check if current php is greater than or +# equal to PHP 7.0: +# +# isPhpVersionGreaterOrEqual 7 0 +# +# Param 1: Specific PHP Major version +# Param 2: Specific PHP Minor version +# Return : 1 if greater than or equal to, 0 if less than +# isPhpVersionGreaterOrEqual() { local PHP_MAJOR_VERSION=$(php -r "echo PHP_MAJOR_VERSION;") @@ -30,6 +43,28 @@ isPhpVersionGreaterOrEqual() } +# +# Install extension from package file(.tgz), +# For example: +# +# installExtensionFromTgz redis-4.1.1 +# +# Param 1: Package name with version +# Param 2: enable options +# +installExtensionFromTgz() +{ + tgzName=$1 + extensionName="${tgzName%%-*}" + + mkdir ${extensionName} + tar -xf ${tgzName}.tgz -C ${extensionName} --strip-components=1 + ( cd ${extensionName} && phpize && ./configure && make ${MC} && make install ) + + docker-php-ext-enable ${extensionName} $2 +} + + if [[ -z "${EXTENSIONS##*,pdo_mysql,*}" ]]; then echo "---------- Install pdo_mysql ----------" docker-php-ext-install ${MC} pdo_mysql @@ -178,24 +213,25 @@ fi if [[ -z "${EXTENSIONS##*,soap,*}" ]]; then echo "---------- Install soap ----------" + apk add --no-cache libxml2-dev docker-php-ext-install ${MC} soap fi if [[ -z "${EXTENSIONS##*,xsl,*}" ]]; then echo "---------- Install xsl ----------" - apk add --no-cache libxslt-dev + apk add --no-cache libxml2-dev libxslt-dev docker-php-ext-install ${MC} xsl fi if [[ -z "${EXTENSIONS##*,xmlrpc,*}" ]]; then echo "---------- Install xmlrpc ----------" - apk add --no-cache libxslt-dev + apk add --no-cache libxml2-dev libxslt-dev docker-php-ext-install ${MC} xmlrpc fi if [[ -z "${EXTENSIONS##*,wddx,*}" ]]; then echo "---------- Install wddx ----------" - apk add --no-cache libxslt-dev + apk add --no-cache libxml2-dev libxslt-dev docker-php-ext-install ${MC} wddx fi @@ -356,9 +392,7 @@ if [[ -z "${EXTENSIONS##*,mysql,*}" ]]; then isPhpVersionGreaterOrEqual 7 0 if [[ "$?" = "1" ]]; then - echo echo "---------- mysql was REMOVED from PHP 7.0.0 ----------" - echo else echo "---------- Install mysql ----------" docker-php-ext-install ${MC} mysql @@ -381,14 +415,12 @@ fi if [[ -z "${EXTENSIONS##*,amqp,*}" ]]; then echo "---------- Install amqp ----------" apk add --no-cache rabbitmq-c-dev - printf "\n" | pecl install amqp-1.9.4.tgz - docker-php-ext-enable amqp + installExtensionFromTgz amqp-1.9.4 fi if [[ -z "${EXTENSIONS##*,redis,*}" ]]; then echo "---------- Install redis ----------" - printf "\n" | pecl install redis-4.1.1.tgz - docker-php-ext-enable redis + installExtensionFromTgz redis-4.1.1 fi if [[ -z "${EXTENSIONS##*,memcached,*}" ]]; then @@ -410,16 +442,15 @@ if [[ -z "${EXTENSIONS##*,xdebug,*}" ]]; then isPhpVersionGreaterOrEqual 7 0 if [[ "$?" = "1" ]]; then - printf "\n" | pecl install xdebug-2.6.1.tgz + installExtensionFromTgz xdebug-2.6.1 else - printf "\n" | pecl install xdebug-2.5.5.tgz + installExtensionFromTgz xdebug-2.5.5 fi - - docker-php-ext-enable xdebug fi if [[ -z "${EXTENSIONS##*,event,*}" ]]; then echo "---------- Install event ----------" + apk add --no-cache libevent-dev export is_sockets_installed=$(php -r "echo extension_loaded('sockets');") if [[ "${is_sockets_installed}" = "" ]]; then @@ -428,14 +459,12 @@ if [[ -z "${EXTENSIONS##*,event,*}" ]]; then fi echo "---------- Install event again ----------" - printf "\n" | pecl install event-2.5.3.tgz - docker-php-ext-enable --ini-name event.ini event + installExtensionFromTgz event-2.5.3 "--ini-name event.ini" fi if [[ -z "${EXTENSIONS##*,mongodb,*}" ]]; then echo "---------- Install mongodb ----------" - printf "\n" | pecl install mongodb-1.5.5.tgz - docker-php-ext-enable mongodb + installExtensionFromTgz mongodb-1.5.5 fi if [[ -z "${EXTENSIONS##*,yaf,*}" ]]; then @@ -444,28 +473,22 @@ if [[ -z "${EXTENSIONS##*,yaf,*}" ]]; then if [[ "$?" = "1" ]]; then printf "\n" | pecl install yaf + docker-php-ext-enable yaf else - # install by pecl may cause error: - # can't create directory 'configs/.libs': No such file or directory - mkdir yaf - tar -xf yaf-2.3.5.tgz -C yaf --strip-components=1 - ( cd yaf && phpize && ./configure && make ${MC} && make install ) + installExtensionFromTgz yaf-2.3.5 fi - - docker-php-ext-enable yaf fi + if [[ -z "${EXTENSIONS##*,swoole,*}" ]]; then echo "---------- Install swoole ----------" isPhpVersionGreaterOrEqual 7 0 if [[ "$?" = "1" ]]; then - printf "\n" | pecl install swoole-4.4.2.tgz + installExtensionFromTgz swoole-4.4.2 else - printf "\n" | pecl install swoole-2.0.11.tgz + installExtensionFromTgz swoole-2.0.11 fi - - docker-php-ext-enable swoole fi if [[ -z "${EXTENSIONS##*,zip,*}" ]]; then