diff --git a/conf/install_postfixadmin.conf.sample b/conf/install_postfixadmin.conf.sample index 9fbfa72..4e9846f 100644 --- a/conf/install_postfixadmin.conf.sample +++ b/conf/install_postfixadmin.conf.sample @@ -93,6 +93,15 @@ APACHE_SERVER_KEY="" # - #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_postfixadmin.sh b/install_postfixadmin.sh index a3e8bcd..a64adf4 100755 --- a/install_postfixadmin.sh +++ b/install_postfixadmin.sh @@ -221,6 +221,7 @@ DOMAIN="${MAIN_DOMAIN}.$TLD" [[ -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 @@ -239,9 +240,6 @@ if [ -x "$httpd_binary" ];then HTTP_USER="`$httpd_binary -t -D DUMP_RUN_CFG | grep -i -e "^User" | awk '{print$2}' | cut -d\"=\" -f2 | tr -d '"'`" HTTP_GROUP="`$httpd_binary -t -D DUMP_RUN_CFG | grep -i -e "^Group" | awk '{print$2}' | cut -d\"=\" -f2 | tr -d '"'`" - [[ -n "$HTTP_USER" ]] || HTTP_USER=$DEFAULT_HTTP_USER - [[ -n "$HTTP_GROUP" ]] || HTTP_GROUP=$DEFAULT_HTTP_GROUP - # - Is webserver running ? # - PID=$(ps aux | grep "$(realpath $httpd_binary)" | grep -e "^root" | grep -v grep | awk '{print$2}') @@ -252,6 +250,9 @@ if [ -x "$httpd_binary" ];then fi fi +[[ -n "$HTTP_USER" ]] || HTTP_USER=$DEFAULT_HTTP_USER +[[ -n "$HTTP_GROUP" ]] || HTTP_GROUP=$DEFAULT_HTTP_GROUP + [[ -n "$WEBMASTER_EMAIL" ]] || fatal "E-Mail (WEBMASTER_EMAIL) for webmaster not present!" [[ -n "$WEBSITE_BASEDIR" ]] || WEBSITE_BASEDIR=$DEFAULT_WEBSITE_BASEDIR @@ -334,32 +335,40 @@ fi # - Determin PHP of all installed versions # - echononl "\tGet major numbers 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 major numbers of installed PHP versions failed! No installed PHP versiond found!" +if $PHP_DEBIAN_INSTALLATION ; then + php_major_version="$(php --version | head -1 | cut -d' ' -f2 | cut -d '-' -f1 | cut -d'.' -f1,2)" 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 major numbers of installed PHP versions failed! No installed PHP versiond found!" + else + echo_ok + fi fi # - Get the latest PHP version # - echononl "\tGet major number 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 number of latest installed PHP version failed! - No installed PHP versiond found!" +else + 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 + echo_skipped + warn "Getting major number of latest installed PHP version failed! - No installed PHP versiond found!" + fi fi @@ -392,8 +401,12 @@ echo -e "\tBase Directory of PFA Website........: $WEBSITE_BASEDIR" echo "" echo -e "\tType of PHP connection...............: $PHP_TYPE" echo "" -echo -e "\tInstalled PHP versions...............: $php_major_versions" -echo -e "\tNewest PHP Version...................: $php_latest_ver" +if $PHP_DEBIAN_INSTALLATION ; then + echo -e "\tInstalled PHP version................: $php_major_version" +else + echo -e "\tInstalled PHP versions...............: $php_major_versions" + echo -e "\tNewest PHP Version...................: $php_latest_ver" +fi echo "" if [[ "$POSTFIX_DB_TYPE" = "mysql" ]]; then echo -e "\tDatabase type of Postfix Database....: MySQL" @@ -680,7 +693,7 @@ if [[ ! -f "${_src_base_dir}/postfixadmin-${PF_ADMIN_VERSION}.tar.gz" ]];then echo_ok else echo_failed - error "$(cat $log_file)" + fatal "$(cat $log_file)" fi else echo_skipped @@ -1284,7 +1297,17 @@ 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/php$(echo $php_major_version | cut -d'.' -f1)-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 + fi + cat <> ${APACHE_VHOST_DIR}/${WEBSITE_NAME}.conf 2>> $log_file @@ -1536,7 +1559,17 @@ 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/php$(echo $php_major_version | cut -d'.' -f1)-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 + fi + cat <> ${APACHE_VHOST_DIR}/${WEBSITE_NAME}.conf 2>> $log_file @@ -1654,6 +1687,7 @@ else echo_ok fi + if $APACHE_DEBIAN_INSTALLATION ; then ## - add to /etc/apache2/ports.conf ## - @@ -3264,6 +3298,52 @@ else error "$(cat $log_file)" fi +# - Start all PHP FPM engines +# - +if [[ -n "$php_major_versions" ]]; then + for _ver in $php_major_versions ; do + echononl " Restart PHP FPM engine v${_ver}.." + if [[ -f "/etc/init.d/php-${_ver}-fpm" ]]; then + /etc/init.d/php-${_ver}-fpm restart > $log_file 2>&1 + if [[ $? -eq 0 ]]; then + echo_ok + else + echo_failed + error "$(cat $log_file)" + fi + elif [[ -f "/etc/systemd/system/php-${_ver}-fpm.service" ]] ; then + systemctl restart php-${_ver}-fpm > $log_file 2>&1 + if [[ $? -eq 0 ]]; then + echo_ok + else + echo_failed + error "$(cat $log_file)" + fi + else + echo_skipped + fi + done +else + if $PHP_DEBIAN_INSTALLATION ; then + echononl " Retart PHP FPM engine v${php_major_version}.." + if [[ -f "/etc/init.d/php$(echo $php_major_version | cut -d'.' -f1)-fpm" ]] ; then + /etc/init.d/php$(echo $php_major_version | cut -d'.' -f1)-fpm restart > $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 "" info "Browse to \033[1mhttp://${WEBSITE_NAME}/setup.php\033[m to create a 'setup password'\n$(cat <