From 186d3b94d534aa2ea74ec24475ddae620d574b2a Mon Sep 17 00:00:00 2001 From: Christoph Date: Mon, 6 Nov 2017 04:24:52 +0100 Subject: [PATCH] Support PHP installed from Debian Packages System. --- conf/install_upgrade_roundcube.conf.sample | 11 ++- install_roundcube.sh | 104 ++++++++++++++++----- upgrade_roundcube.sh | 52 +++++++++-- 3 files changed, 136 insertions(+), 31 deletions(-) diff --git a/conf/install_upgrade_roundcube.conf.sample b/conf/install_upgrade_roundcube.conf.sample index efbf72f..a250f76 100644 --- a/conf/install_upgrade_roundcube.conf.sample +++ b/conf/install_upgrade_roundcube.conf.sample @@ -47,7 +47,7 @@ IPV6="" # - Note: it's not the 'DocumentRoot' directory, but the directory where # - the 'DocumentRoot' Directory lives. # - -# - Defaults to '/var/www/webmail/$WEBSITE_NAME' +# - Defaults to '/var/www/$WEBSITE_NAME' # - #WEBSITE_BASEDIR="" @@ -100,6 +100,15 @@ IPV6="" # - #CERT_ChainFile="" + +# - Is PHP installed from debian package system ? +# - +# - Boolean, possible values are 'true', 'false' +# - +# - Defaults to 'false' +# +#PHP_DEBIAN_INSTALLATION="" + # - Type of PHP installation. # - # - Possible values are: 'php_fpm' , 'fcgid' , 'mod_php diff --git a/install_roundcube.sh b/install_roundcube.sh index 1d92063..02a7243 100755 --- a/install_roundcube.sh +++ b/install_roundcube.sh @@ -157,6 +157,7 @@ MAIN_DOMAIN=${_tmp_string##*.} [[ -n "$IPV6" ]] || fatal "IPv4 Address (IPV6) not present!" [[ -n "$APACHE_DEBIAN_INSTALLATION" ]] || APACHE_DEBIAN_INSTALLATION=false +[[ -n "$PHP_DEBIAN_INSTALLATION" ]] || PHP_DEBIAN_INSTALLATION=false httpd_binary="`which httpd`" if [ -z "$httpd_binary" ]; then @@ -305,20 +306,24 @@ fi # - echononl "\tGet major version of latest installed PHP version" php_latest_ver="" -if [[ -n "$php_major_versions" ]]; then - for _ver in $php_major_versions ; do - if [[ -z "$php_latest_ver" ]] ; then - php_latest_ver=$_ver - elif [[ "${_ver%.*}" -gt "${php_latest_ver%.*}" ]] ; then - php_latest_ver=$_ver - elif [[ "${_ver%.*}" -eq "${php_latest_ver%.*}" ]] ; then - [[ "${_ver#*.}" -gt "${php_latest_ver#*.}" ]] && php_latest_ver=$_ver - fi - done - echo_ok -else +if $PHP_DEBIAN_INSTALLATION ; then echo_skipped - warn "Getting major version of latest installed PHP version failed! - No installed PHP versiond found!" +else + if [[ -n "$php_major_versions" ]]; then + for _ver in $php_major_versions ; do + if [[ -z "$php_latest_ver" ]] ; then + php_latest_ver=$_ver + elif [[ "${_ver%.*}" -gt "${php_latest_ver%.*}" ]] ; then + php_latest_ver=$_ver + elif [[ "${_ver%.*}" -eq "${php_latest_ver%.*}" ]] ; then + [[ "${_ver#*.}" -gt "${php_latest_ver#*.}" ]] && php_latest_ver=$_ver + fi + done + echo_ok + else + echo_skipped + warn "Getting major version of latest installed PHP version failed! - No installed PHP versiond found!" + fi fi echo "" @@ -445,14 +450,13 @@ fi ## - ## - !! Take care to do this for all php installations (PHP 5.5/5.6/..) ## - -for _version in $php_major_versions ; do - - echo -e "\n\n\t\033[37m\033[1mInstall modules for PHP Version ${_version}..\033[m\n" +echo -e "\n\n\t\033[37m\033[1mInstall modules for PHP Version ${_version}..\033[m\n" +if $PHP_DEBIAN_INSTALLATION ; then for _module in $needed_php_pear_modules ; do echononl "\tInstall Module '$_module'.." - if ! /usr/local/php-${_version}/bin/pear list | grep -q "$_module" 2> /dev/null ; then - /usr/local/php-${_version}/bin/pear install $_module > $log_file 2>&1 + if ! pear list | grep -q "$_module" 2> /dev/null ; then + pear install $_module > $log_file 2>&1 if [[ "$?" = "0" ]]; then echo_ok else @@ -460,7 +464,7 @@ for _version in $php_major_versions ; do error "$(cat $log_file)" if [[ "$_module" = "Net_IDNA2" ]]; then echononl "\tInstall (beta) Net_IDNA2-0.1.1 .." - /usr/local/php-${_version}/bin/pear install channel://pear.php.net/Net_IDNA2-0.1.1 > $log_file 2>&1 + pear install channel://pear.php.net/Net_IDNA2-0.1.1 > $log_file 2>&1 if [ "$?" = "0" ]; then echo_ok else @@ -473,7 +477,36 @@ for _version in $php_major_versions ; do echo_skipped fi done -done + +else + for _version in $php_major_versions ; do + + for _module in $needed_php_pear_modules ; do + echononl "\tInstall Module '$_module'.." + if ! /usr/local/php-${_version}/bin/pear list | grep -q "$_module" 2> /dev/null ; then + /usr/local/php-${_version}/bin/pear install $_module > $log_file 2>&1 + if [[ "$?" = "0" ]]; then + echo_ok + else + echo_failed + error "$(cat $log_file)" + if [[ "$_module" = "Net_IDNA2" ]]; then + echononl "\tInstall (beta) Net_IDNA2-0.1.1 .." + /usr/local/php-${_version}/bin/pear install channel://pear.php.net/Net_IDNA2-0.1.1 > $log_file 2>&1 + if [ "$?" = "0" ]; then + echo_ok + else + echo_failed + error "$(cat $log_file)" + fi + fi + fi + else + echo_skipped + fi + done + done +fi echo -e "\n\n\t\033[37m\033[1mInstall (global) composer..\033[m\n" @@ -639,10 +672,15 @@ fi echononl "\tInstall PHP dependencies.." -#/usr/local/php-${php_latest_ver}/bin/php /usr/local/bin/composer install --no-dev -su www-data -c"cd ${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION} - /usr/local/php-${php_latest_ver}/bin/php /usr/local/bin/composer install --no-dev" -s /bin/bash \ - > $log_file 2>&1 +if $PHP_DEBIAN_INSTALLATION ; then + su ${HTTP_USER} -c"cd ${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION} + php /usr/local/bin/composer install --no-dev" -s /bin/bash \ + > $log_file 2>&1 +else + su ${HTTP_USER} -c"cd ${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION} + /usr/local/php-${php_latest_ver}/bin/php /usr/local/bin/composer install --no-dev" -s /bin/bash \ + > $log_file 2>&1 +fi if [[ $? -eq 0 ]]; then echo_ok else @@ -1253,7 +1291,16 @@ elif [[ "$PHP_TYPE" = "php_fpm" ]]; then DocumentRoot "${WEBSITE_BASEDIR}/htdocs/" +EOF + if $PHP_DEBIAN_INSTALLATION ; then + cat <> ${APACHE_VHOST_DIR}/${WEBSITE_NAME}.conf 2>> $log_file + SetHandler "proxy:unix:/var/run/php5-fpm.sock|fcgi://127.0.0.1" +EOF + else + cat <> ${APACHE_VHOST_DIR}/${WEBSITE_NAME}.conf 2>> $log_file SetHandler "proxy:unix:/tmp/php-${php_latest_ver}-fpm.www.sock|fcgi://127.0.0.1" +EOF + cat <> ${APACHE_VHOST_DIR}/${WEBSITE_NAME}.conf 2>> $log_file @@ -1506,7 +1553,16 @@ elif [[ "$PHP_TYPE" = "php_fpm" ]]; then DocumentRoot "${WEBSITE_BASEDIR}/htdocs/" +EOF + if $PHP_DEBIAN_INSTALLATION ; then + cat <> ${APACHE_VHOST_DIR}/${WEBSITE_NAME}.conf 2>> $log_file + SetHandler "proxy:unix:/var/run/php5-fpm.sock|fcgi://127.0.0.1" +EOF + else + cat <> ${APACHE_VHOST_DIR}/${WEBSITE_NAME}.conf 2>> $log_file SetHandler "proxy:unix:/tmp/php-${php_latest_ver}-fpm.www.sock|fcgi://127.0.0.1" +EOF + cat <> ${APACHE_VHOST_DIR}/${WEBSITE_NAME}.conf 2>> $log_file diff --git a/upgrade_roundcube.sh b/upgrade_roundcube.sh index 386b719..ddae2b3 100755 --- a/upgrade_roundcube.sh +++ b/upgrade_roundcube.sh @@ -354,19 +354,23 @@ fi # - Determin PHP of all installed versions # - echononl "\tGet major version of all installed PHP versions" -php_major_versions="$(find /usr/local/ -maxdepth 1 -mindepth 1 -type l -name "php-*" -print | cut -d "-" -f2 | sort)" -if [[ -z "$php_major_versions" ]]; then - echo_failed - error "Getting version numbers of installed PHP versions failed! No installed PHP versiond found!" +if $PHP_DEBIAN_INSTALLATION ; then + echo_skipped else - echo_ok + php_major_versions="$(find /usr/local/ -maxdepth 1 -mindepth 1 -type l -name "php-*" -print | cut -d "-" -f2 | sort)" + if [[ -z "$php_major_versions" ]]; then + echo_failed + error "Getting version numbers of installed PHP versions failed! No installed PHP versiond found!" + else + echo_ok + fi fi # - Stop all PHP FPM engines # - +echononl " Stop PHP FPM engine v${_ver}.." if [[ -n "$php_major_versions" ]]; then for _ver in $php_major_versions ; do - echononl " Stop PHP FPM engine v${_ver}.." if [[ -f "/etc/init.d/php-${_ver}-fpm" ]]; then /etc/init.d/php-${_ver}-fpm stop > $log_file 2>&1 if [[ $? -eq 0 ]]; then @@ -387,6 +391,24 @@ if [[ -n "$php_major_versions" ]]; then echo_skipped fi done +else + if $PHP_DEBIAN_INSTALLATION ; then + if [[ -f "/etc/init.d/php5-fpm" ]] ; then + /etc/init.d/php5-fpm stop > $log_file 2>&1 + elif [[ -f "/etc/init.d/php7-fpm" ]] ; then + /etc/init.d/php7-fpm stop > $log_file 2>&1 + else + echo_skipped + fi + if [[ $? -eq 0 ]]; then + echo_ok + else + echo_failed + error "$(cat $log_file)" + fi + else + echo_skipped + fi fi echo -e "\n\n \033[37m\033[1mUgrade Roundcube Webmail..\033[m\n" @@ -524,6 +546,24 @@ if [[ -n "$php_major_versions" ]]; then echo_skipped fi done +else + if $PHP_DEBIAN_INSTALLATION ; then + if [[ -f "/etc/init.d/php5-fpm" ]] ; then + /etc/init.d/php5-fpm start > $log_file 2>&1 + elif [[ -f "/etc/init.d/php7-fpm" ]] ; then + /etc/init.d/php7-fpm start > $log_file 2>&1 + else + echo_skipped + fi + if [[ $? -eq 0 ]]; then + echo_ok + else + echo_failed + error "$(cat $log_file)" + fi + else + echo_skipped + fi fi # - Start Apache Webserver