From 2f91eee76db51c615e413b7b5b87b7780e9d8a8e Mon Sep 17 00:00:00 2001 From: Alexey Berezhok Date: Fri, 17 Jan 2025 21:33:34 +0300 Subject: [PATCH] Use local php. Part 2 --- bin/v-add-web-php | 136 ++++++++++++++++++++++++------------------- bin/v-change-sys-php | 52 +++++++++-------- 2 files changed, 104 insertions(+), 84 deletions(-) diff --git a/bin/v-add-web-php b/bin/v-add-web-php index fe46733..a33cd3c 100755 --- a/bin/v-add-web-php +++ b/bin/v-add-web-php @@ -38,27 +38,22 @@ if [ -z "$WEB_BACKEND" ]; then fi # Set file locations -if [ -f /etc/redhat-release ]; then - php_fpm="/usr/lib/systemd/system/php$version-php-fpm.service" +php_fpm="" +if [ "$LOCAL_PHP" == "yes" ]; then + php_fpm="/usr/lib/systemd/system/brepo-php-fpm$version.service" else - php_fpm="/etc/init.d/php$version-fpm" + php_fpm="/usr/lib/systemd/system/php$version-php-fpm.service" fi + # Verify php version format -if [ -f /etc/redhat-release ]; then - if [[ ! $version =~ ^[0-9][0-9]+ ]]; then - echo "The specified PHP version format is invalid, it should look like [0-9][0-9]." - echo "Example: 70, 74, 80" - exit "$E_INVALID" - fi -else - if [[ ! $version =~ ^[0-9].[0-9]+ ]]; then - echo "The specified PHP version format is invalid, it should look like [0-9].[0-9]." - echo "Example: 7.0, 7.4, 8.0" - exit "$E_INVALID" - fi +if [[ ! $version =~ ^[0-9][0-9]+ ]]; then + echo "The specified PHP version format is invalid, it should look like [0-9][0-9]." + echo "Example: 70, 74, 80" + exit "$E_INVALID" fi + # Check if php version already exists if [ -f "$php_fpm" ] && [ -f "$HESTIA/data/templates/web/php-fpm/PHP-${version/\./_}.tpl" ]; then echo "ERROR: Specified PHP version is already installed." @@ -77,39 +72,44 @@ check_hestia_demo_mode #----------------------------------------------------------# # Action # #----------------------------------------------------------# +mph="" +php_modules_install="mysqlnd mysqli pdo_mysql pgsql pdo sqlite pdo_sqlite pdo_pgsql imap ldap zip opcache xmlwriter xmlreader gd intl pspell" +php_modules_disable="" +if [ "$LOCAL_PHP" == "yes" ]; then + mph="brepo-php$version brepo-php$version-fpm" + if ! echo "$DB_SYSTEM" | grep -w 'pgsql' > /dev/null; then + php_modules_install=$(echo "$php_modules_install" | sed -e "s/pgsql//") + php_modules_install=$(echo "$php_modules_install" | sed -e "s/pdo_pgsql//") + php_modules_disable="$php_modules_disable pgsql pdo_pgsql" + fi +else + # Packages in Remi repo have names with php$version-php- prefixes + mph="php$version-php-fpm php$version-php-cgi php$version-php-mysqlnd php$version-php-pgsql + php$version-php-pdo php$version-php-common php$version-php-pecl-imagick php$version-php-imap + php$version-php-ldap php$version-php-pecl-apcu php$version-php-pecl-zip php$version-php-cli + php$version-php-opcache php$version-php-xml php$version-php-gd php$version-php-intl + php$version-php-mbstring php$version-php-pspell php$version-php-readline" + if [ "$version" = "56" ]; then + mph=$(sed -e "s/php$version-php-pecl-apcu//") + fi -mph="php$version-common php$version-mbstring php$version-bcmath php$version-cli php$version-curl - php$version-fpm php$version-gd php$version-intl php$version-mysql - php$version-soap php$version-xml php$version-zip php$version-json php$version-bz2 - php$version-pspell php$version-imagick php$version-pgsql php$version-imap php$version-ldap" -if [ -f /etc/redhat-release ]; then - # Packages in Remi repo have names with php$version-php- prefixes - mph="php$version-php-fpm php$version-php-cgi php$version-php-mysqlnd php$version-php-pgsql - php$version-php-pdo php$version-php-common php$version-php-pecl-imagick php$version-php-imap - php$version-php-ldap php$version-php-pecl-apcu php$version-php-pecl-zip php$version-php-cli - php$version-php-opcache php$version-php-xml php$version-php-gd php$version-php-intl - php$version-php-mbstring php$version-php-pspell php$version-php-readline" - if [ "$version" = "56" ]; then - mph=$(sed -e "s/php$version-php-pecl-apcu//") - fi -fi - -# Check is version is 7.1 or below to add mcrypt -if [[ $(echo "$version 7.2" | awk '{print ($1 < $2)}') == 1 ]]; then - mph="$mph php$version-mcrypt" -fi + # Check is version is 7.1 or below to add mcrypt + if [[ $(echo "$version 7.2" | awk '{print ($1 < $2)}') == 1 ]]; then + mph="$mph php$version-mcrypt" + fi -# Check if version is 8.0 or higher and drop php json. -if [[ ${version:0:1} == "8" ]]; then - mph=$(echo "$mph" | sed -e "s/php$version\(-php\)\{0,1\}-json//") -fi + # Check if version is 8.0 or higher and drop php json. + if [[ ${version:0:1} == "8" ]]; then + mph=$(echo "$mph" | sed -e "s/php$version\(-php\)\{0,1\}-json//") + fi -if ! echo "$DB_SYSTEM" | grep -w 'mysql' > /dev/null; then - mph=$(echo "$mph" | sed -e "s/php$version\(-php\)\{0,1\}-mysql//") -fi + if ! echo "$DB_SYSTEM" | grep -w 'mysql' > /dev/null; then + mph=$(echo "$mph" | sed -e "s/php$version\(-php\)\{0,1\}-mysql//") + fi -if ! echo "$DB_SYSTEM" | grep -w 'pgsql' > /dev/null; then - mph=$(echo "$mph" | sed -e "s/php$version\(-php\)\{0,1\}-pgsql//") + if ! echo "$DB_SYSTEM" | grep -w 'pgsql' > /dev/null; then + mph=$(echo "$mph" | sed -e "s/php$version\(-php\)\{0,1\}-pgsql//") + fi fi # Install php packages @@ -128,18 +128,33 @@ done # Do a blank echo to get the \n back echo +if [ "$LOCAL_PHP" == "yes" ]; then + for mod in $php_modules_install; do + enable_local_php_extension "$version" "$mod" + done + for mod in $php_modules_disable; do + disable_local_php_extension "$version" "$mod" + done +fi + # Check if installation was successful if [ ! -f "$php_fpm" ]; then echo "ERROR: Installation failed, please run the following command manually for debugging:" echo "dnf install $mph" fi -result_alt_php=$(alternatives --display php | grep /usr/bin/php$version) -if [ -z "$result_alt_php" ]; then - alternatives --install /usr/bin/php php /usr/bin/php$version 1 > /dev/null 2>&1 +if [ "$LOCAL_PHP" == "yes" ]; then + result_alt_php=$(alternatives --display php | grep /opt/brepo/php${version}/bin/php) + if [ -z "$result_alt_php" ]; then + alternatives --install /usr/bin/php php /opt/brepo/php${version}/bin/php 1 > /dev/null 2>&1 + fi +else + result_alt_php=$(alternatives --display php | grep /usr/bin/php$version) + if [ -z "$result_alt_php" ]; then + alternatives --install /usr/bin/php php /usr/bin/php$version 1 > /dev/null 2>&1 + fi fi - # Check if required modules for apache2 are enabled if [ "$WEB_SYSTEM" = "apache2" ]; then if [ -f /etc/redhat-release ]; then @@ -163,7 +178,17 @@ fi # Configure fpm v_tpl=${version//./} -if [ -f /etc/redhat-release ]; then +if [ "$LOCAL_PHP" == "yes" ]; then + systemctl enable brepo-php-fpm${version}.service + rm -f /opt/brepo/php${version}/etc/php-fpm.d/* + cp -f $HESTIA_INSTALL_DIR/php-fpm/dummy.conf /opt/brepo/php${version}/etc/php-fpm.d/ + sed -i "s/9999/99$v_tpl/g" /opt/brepo/php${version}/etc/php-fpm.d/dummy.conf + + # Increase max upload and max post size + sed -i "s/upload_max_filesize = 2M/upload_max_filesize = 100M/g" /opt/brepo/php${version}/etc/php.ini + sed -i "s/post_max_size = 8M/post_max_size = 100M/g" /opt/brepo/php${version}/etc/php.ini + sed -i "s/max_execution_time = 30/max_execution_time = 60/g" /opt/brepo/php${version}/etc/php.ini +else systemctl enable php${version}-php-fpm rm -f /etc/opt/remi/php${version}/php-fpm.d/* cp -f $HESTIA_INSTALL_DIR/php-fpm/dummy.conf /etc/opt/remi/php${version}/php-fpm.d/ @@ -173,19 +198,8 @@ if [ -f /etc/redhat-release ]; then sed -i "s/upload_max_filesize = 2M/upload_max_filesize = 100M/g" /etc/opt/remi/php${version}/php.ini sed -i "s/post_max_size = 8M/post_max_size = 100M/g" /etc/opt/remi/php${version}/php.ini sed -i "s/max_execution_time = 30/max_execution_time = 60/g" /etc/opt/remi/php${version}/php.ini -else - update-rc.d php$version-fpm defaults > /dev/null 2>&1 - rm -f /etc/php/$version/fpm/pool.d/* - cp -f $HESTIA_INSTALL_DIR/php-fpm/dummy.conf /etc/php/$version/fpm/pool.d/ - sed -i "s/9999/99$v_tpl/g" /etc/php/$version/fpm/pool.d/dummy.conf - cp -f $HESTIA_INSTALL_DIR/php-fpm/php-fpm.conf /etc/php/$version/fpm/ - sed -i "s/fpm_v/$version/g" /etc/php/$version/fpm/php-fpm.conf - - # Increase max upload and max post size - sed -i "s/upload_max_filesize = 2M/upload_max_filesize = 100M/g" /etc/php/$version/fpm/php.ini - sed -i "s/post_max_size = 8M/post_max_size = 100M/g" /etc/php/$version/fpm/php.ini - sed -i "s/max_execution_time = 30/max_execution_time = 60/g" /etc/php/$version/fpm/php.ini fi + # Install backend template cp -f $HESTIA_INSTALL_DIR/php-fpm/multiphp.tpl \ $HESTIA/data/templates/web/php-fpm/PHP-${version/\./_}.tpl diff --git a/bin/v-change-sys-php b/bin/v-change-sys-php index 62053e6..7718ce0 100755 --- a/bin/v-change-sys-php +++ b/bin/v-change-sys-php @@ -21,18 +21,10 @@ source_conf "$HESTIA/conf/hestia.conf" check_args '1' "$#" 'VERSION' # Verify php version format -if [ -f /etc/redhat-release ]; then - if [[ ! $version =~ ^[0-9][0-9]+ ]]; then - echo "The specified PHP version format is invalid, it should look like [0-9][0-9]." - echo "Example: 70, 74, 80" - exit "$E_INVALID" - fi -else - if [[ ! $version =~ ^[0-9].[0-9]+ ]]; then - echo "The specified PHP version format is invalid, it should look like [0-9].[0-9]." - echo "Example: 7.0, 7.4, 8.0" - exit "$E_INVALID" - fi +if [[ ! $version =~ ^[0-9][0-9]+ ]]; then + echo "The specified PHP version format is invalid, it should look like [0-9][0-9]." + echo "Example: 70, 74, 80" + exit "$E_INVALID" fi # Check if php version exists @@ -50,18 +42,19 @@ check_hestia_demo_mode #----------------------------------------------------------# # Set file locations -if [ -f /etc/redhat-release ]; then - php_fpm="/usr/lib/systemd/system/php$version-php-fpm.service" +php_fpm="" +if [ "$LOCAL_PHP" == "yes" ]; then + php_fpm="/usr/lib/systemd/system/brepo-php-fpm$version.service" else - php_fpm="/etc/init.d/php$version-fpm" + php_fpm="/usr/lib/systemd/system/php$version-php-fpm.service" fi -if [ -f /etc/redhat-release ]; then +if [ "$LOCAL_PHP" == "yes" ]; then + rm -f /opt/brepo/php*/etc/php-fpm.d/ + cp -f $HESTIA/install/rpm/php-fpm/www.conf /opt/brepo/php${version}/etc/php-fpm.d/www.conf +else rm -f /etc/opt/remi/php*/php-fpm.d/www.conf cp -f $HESTIA/install/rpm/php-fpm/www.conf /etc/opt/remi/php$version/php-fpm.d/www.conf -else - rm -f /etc/php/*/fpm/pool.d/www.conf - cp -f $HESTIA/install/deb/php-fpm/www.conf /etc/php/$version/fpm/pool.d/www.conf fi for user in $($BIN/v-list-sys-users plain); do @@ -75,17 +68,30 @@ $BIN/v-restart-web-backend $BIN/v-restart-web $BIN/v-restart-proxy -if [ -f '/etc/redhat-release' ]; then +if [ "$LOCAL_PHP" == "yes" ]; then + result_alt_php=$(alternatives --display php | grep /opt/brepo/php${version}/bin/php) + if [ -z "$result_alt_php" ]; then + alternatives --install /usr/bin/php php /opt/brepo/php${version}/bin/php 1 > /dev/null 2>&1 + fi +else result_alt_php=$(alternatives --display php | grep /usr/bin/php$version) if [ -z "$result_alt_php" ]; then alternatives --install /usr/bin/php php /usr/bin/php$version 1 > /dev/null 2>&1 fi fi -update-alternatives --set php /usr/bin/php$version -if [ $? -eq 0 ]; then - update-alternatives --install /usr/bin/php php /usr/bin/php$version 1 +if [ "$LOCAL_PHP" == "yes" ]; then + update-alternatives --set php /opt/brepo/php${version}/bin/php + if [ $? -eq 0 ]; then + update-alternatives --install /usr/bin/php php /opt/brepo/php${version}/bin/php 1 + update-alternatives --set php /opt/brepo/php${version}/bin/php + fi +else update-alternatives --set php /usr/bin/php$version + if [ $? -eq 0 ]; then + update-alternatives --install /usr/bin/php php /usr/bin/php$version 1 + update-alternatives --set php /usr/bin/php$version + fi fi /usr/bin/hestiacp-php-admin system $version