Use local php. Part 3

devel
Alexey Berezhok 3 months ago
parent 2f91eee76d
commit f3b9d33016

@ -52,11 +52,13 @@ get_domain_values 'web'
BACKEND="$template"
# Defining pool directory
if [ -f "/etc/redhat-release" ]; then
pool=$(find -L /etc/opt/remi/ -name "$domain.conf" -exec dirname {} \;)
pool=""
if [ "$LOCAL_PHP" == "yes" ]; then
pool=$(find -L /opt/brepo/ -name "$domain.conf" -exec dirname {} \;)
else
pool=$(find -L /etc/php/ -name "$domain.conf" -exec dirname {} \;)
pool=$(find -L /etc/opt/remi/ -name "$domain.conf" -exec dirname {} \;)
fi
if [ ! -e "$pool" ]; then
check_result "$E_NOTEXIST" "php-fpm pool doesn't exist"
fi

@ -32,27 +32,21 @@ 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 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 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 PHP version format is invalid, it should look like [0-9][0-9]."
echo "Example: 70, 74, 80"
exit "$E_INVALID"
fi
# Remove backend template
[ -f $HESTIA/data/templates/web/php-fpm/PHP-${version/\./_}.tpl ] && rm -f $HESTIA/data/templates/web/php-fpm/PHP-${version/\./_}.tpl
@ -70,38 +64,33 @@ check_hestia_demo_mode
# Action #
#----------------------------------------------------------#
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-mbstring
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"
fi
# Check is version is 7.1 or below to add mcrypt
if [ -f /etc/redhat-release ]; then
if [[ $(echo "$version 72" | awk '{print ($1 < $2)}') == 1 ]]; then
mph="$mph php$version-php-mcrypt"
fi
mph=""
if [ "$LOCAL_PHP" == "yes" ]; then
mph="brepo-php$version brepo-php$version-fpm"
else
if [[ $(echo "$version 7.2" | awk '{print ($1 < $2)}') == 1 ]]; then
mph="$mph php$version-mcrypt"
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-mbstring
php$version-json php$version-bz2 php$version-pspell php$version-imagick php$version-pgsql
php$version-imap php$version-ldap"
# 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"
# Check is version is 7.1 or below to add mcrypt
if [[ $(echo "$version 72" | awk '{print ($1 < $2)}') == 1 ]]; then
mph="$mph php$version-php-mcrypt"
fi
fi
# Purge php packages
if [ -f '/etc/redhat-release' ]; then
dnf remove -y $mph > /dev/null 2>&1 &
else
apt-get -y purge $mph > /dev/null 2>&1 &
fi
dnf remove -y $mph > /dev/null 2>&1 &
BACK_PID=$!
# Check if package removal is done, print a spinner
@ -119,40 +108,36 @@ echo
# Check if installation was successfully
if [ -f "$php_fpm" ]; then
echo "ERROR: Uninstallation failed, please run the following command manually for debugging:"
if [ -f '/etc/redhat-release' ]; then
echo "dnf remove $mph"
else
echo "apt-get purge $mph"
fi
echo "dnf remove $mph"
exit 1
fi
# Cleanup php folder
if [ -f '/etc/redhat-release' ]; then
[[ -d /etc/opt/remi/php$version ]] && rm -rf "/etc/opt/remi/php$version"
if [ "$LOCAL_PHP" == "yes" ]; then
[[ -d /opt/brepo/php$version ]] && rm -rf "/opt/brepo/php$version"
else
[[ -d /etc/php/$version ]] && rm -rf "/etc/php/$version"
[[ -d /etc/opt/remi/php$version ]] && rm -rf "/etc/opt/remi/php$version"
fi
if [ -f '/etc/redhat-release' ]; then
if [ "$LOCAL_PHP" == "yes" ]; then
if [ "$WEB_BACKEND" = "php-fpm" ]; then
conf=$(find /etc/opt/remi/php* -name www.conf)
conf=$(find /opt/brepo/php* -name www.conf)
# Check if www.conf exists
if [ -z "$conf" ]; then
# If not grab the "last php version
last=$($BIN/v-list-sys-php "shell" | tail -n1)
cp -f $HESTIA/install/rpm/php-fpm/www.conf /etc/opt/remi/php$version/php-fpm.d/www.conf
cp -f $HESTIA/install/rpm/php-fpm/www.conf /opt/brepo/php$last/etc/php-fpm.d/www.conf
$BIN/v-restart-web-backend
fi
fi
else
if [ "$WEB_BACKEND" = "php-fpm" ]; then
conf=$(find /etc/php* -name www.conf)
conf=$(find /etc/opt/remi/php* -name www.conf)
# Check if www.conf exists
if [ -z "$conf" ]; then
# If not grab the "last php version
last=$($BIN/v-list-sys-php "shell" | tail -n1)
cp -f $HESTIA/install/deb/php-fpm/www.conf /etc/php/$last/fpm/pool.d/www.conf
cp -f $HESTIA/install/rpm/php-fpm/www.conf /etc/opt/remi/php$last/php-fpm.d/www.conf
$BIN/v-restart-web-backend
fi
fi

@ -67,14 +67,14 @@ csv_list() {
declare -a versions
# List through /etc/php
if [ -f /etc/redhat-release ]; then
for version in /etc/opt/remi/php*/php-fpm.d/www.conf; do
ver=$(echo "$version" | awk -F"/" '{ print $5 }' | sed "s/php\([[:digit:]]\+\)/\1/g")
if [ "$LOCAL_PHP" == "yes" ]; then
for version in /opt/brepo/php*/etc/php-fpm.d/www.conf; do
ver=$(echo "$version" | awk -F"/" '{ print $4 }' | sed "s/php\([[:digit:]]\+\)/\1/g")
versions+=("$ver")
done
else
for version in /etc/php/*/fpm/pool.d/www.conf; do
ver=$(echo "$version" | awk -F"/" '{ print $4 }')
for version in /etc/opt/remi/php*/php-fpm.d/www.conf; do
ver=$(echo "$version" | awk -F"/" '{ print $5 }' | sed "s/php\([[:digit:]]\+\)/\1/g")
versions+=("$ver")
done
fi

@ -67,21 +67,29 @@ csv_list() {
declare -a versions
# List through /etc/php
if [ -f /etc/redhat-release ]; then
for version in /etc/opt/remi/php*/; do
ver=$(echo "$version" | awk -F"/" '{ print $5 }' | sed 's|php||')
versions+=("$ver")
done
if [ "$LOCAL_PHP" == "yes" ]; then
if [ -n "$WEB_BACKEND" ]; then
for version in /opt/brepo/php*/; do
ver=$(echo "$version" | awk -F"/" '{ print $4 }' | sed 's|php||')
versions+=("$ver")
done
else
# Fix for modphp
for version in /opt/brepo/php*/bin/php; do
ver=$(echo "$version" | awk -F"/" '{ print $4 }' | sed 's|php||')
versions+=("$ver")
done
fi
else
if [ -n "$WEB_BACKEND" ]; then
for version in /etc/php/*/fpm; do
ver=$(echo "$version" | awk -F"/" '{ print $4 }')
for version in /etc/opt/remi/php*/; do
ver=$(echo "$version" | awk -F"/" '{ print $5 }' | sed 's|php||')
versions+=("$ver")
done
else
# Fix for modphp
for version in /etc/php/*/cli; do
ver=$(echo "$version" | awk -F"/" '{ print $4 }')
for version in /opt/remi/php*/root/bin/php; do
ver=$(echo "$version" | awk -F"/" '{ print $4 }' | sed 's|php||')
versions+=("$ver")
done
fi

@ -63,22 +63,23 @@ csv_list() {
#----------------------------------------------------------#
# Defining config path
if [ -f /etc/redhat-release ]; then
config_path=$(find /etc/opt/remi/php* -name php.ini)
if [ "$LOCAL_PHP" == "yes" ]; then
config_path=$(find /opt/brepo/php* -name php.ini)
else
config_path=$(find /etc/php* -name php.ini)
config_path=$(find /etc/opt/remi/php* -name php.ini)
fi
config_count=$(echo "$config_path" | wc -l)
if [ "$config_count" -gt 1 ]; then
if [ -f /etc/redhat-release ]; then
multiphp_versions=$(ls -d /etc/opt/remi/php*/php-fpm.d 2> /dev/null | wc -l)
if [ "$LOCAL_PHP" == "yes" ]; then
multiphp_versions=$(ls -d /opt/brepo/php*/etc/php-fpm.d 2> /dev/null | wc -l)
else
multiphp_versions=$(ls -d /etc/php/*/fpm/pool.d 2> /dev/null | wc -l)
multiphp_versions=$(ls -d /etc/opt/remi/php*/php-fpm.d 2> /dev/null | wc -l)
fi
if [ "$WEB_BACKEND" = 'php-fpm' ] || [ "$multiphp_versions" -gt 0 ]; then
config_path=$(echo "$config_path" | grep fpm)
else
config_path=$(echo "$config_path" | grep apache)
config_path=$(echo "$config_path" | grep httpd)
fi
fi

@ -86,7 +86,7 @@ get_srv_state() {
rtime="0"
# Searching related pids
if [ -f /etc/redhat-release ] && [ "$name" = "php-fpm" ]; then
if [ "$name" = "php-fpm" ]; then
pids=''
for php_pid in $(pidof php-fpm); do
process_info=$(ps -p "$php_pid" -o args | tail -n1 | grep "$srv")
@ -174,8 +174,8 @@ fi
# Checking PHP intepreter
if [ -n "$WEB_BACKEND" ] && [ "$WEB_BACKEND" != 'remote' ]; then
if [ -f /etc/redhat-release ]; then
php_versions=$(ls /opt/remi/php*/root/sbin/php-fpm | cut -d'/' -f4 | sed 's|php||')
if [ "$LOCAL_PHP" == "yes" ]; then
php_versions=$(/opt/brepo/php*/sbin/php-fpm | cut -d'/' -f4 | sed 's|php||')
for version in $php_versions; do
proc_name="php-fpm"
service_name="php${version}"
@ -184,12 +184,12 @@ if [ -n "$WEB_BACKEND" ] && [ "$WEB_BACKEND" != 'remote' ]; then
data="$data CPU='$cpu' MEM='$mem' RTIME='$rtime'"
done
else
php_versions=$(ls /usr/sbin/php*fpm* | cut -d'/' -f4 | sed 's|php-fpm||')
php_versions=$(ls /opt/remi/php*/root/sbin/php-fpm | cut -d'/' -f4 | sed 's|php||')
for version in $php_versions; do
proc_name="php-fpm${version}"
service_name="php${version}-fpm"
get_srv_state "$service_name" "$proc_name"
data="$data\nNAME='$service_name' SYSTEM='php interpreter' STATE='$state'"
proc_name="php-fpm"
service_name="php${version}"
get_srv_state "$proc_name"
data="$data\nNAME='$service_name-php-fpm' SYSTEM='php interpreter' STATE='$state'"
data="$data CPU='$cpu' MEM='$mem' RTIME='$rtime'"
done
fi

@ -58,21 +58,21 @@ tmpfile=$(mktemp)
if [ -z "$version" ]; then
# Substitute php-fpm service name formats
for version in $($BIN/v-list-sys-php plain); do
if [ -f /etc/redhat-release ]; then
v_php="php$version-php-fpm"
if [ "$LOCAL_PHP" == "yes" ]; then
v_php="brepo-php-fpm$version"
else
v_php="php$version-fpm"
v_php="php$version-php-fpm"
fi
if [ -f /etc/redhat-release ]; then
if [ "$LOCAL_PHP" == "yes" ]; then
if [ ! -f "/opt/brepo/php${version}/etc/php-fpm.d/dummy.conf" ]; then
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
fi
else
if [ ! -f "/etc/opt/remi/php${version}/php-fpm.d/dummy.conf" ]; then
cp -f $HESTIA_INSTALL_DIR/php-fpm/dummy.conf /etc/opt/remi/php${version}/php-fpm.d/
sed -i "s/9999/99$v_tpl/g" /etc/opt/remi/php${version}/php-fpm.d/dummy.conf
fi
else
if [ ! -f "/etc/php/${version}/fpm/pool.d/dummy.conf" ]; then
cp -f "$HESTIA_INSTALL_DIR/php-fpm/dummy.conf" "/etc/php/${version}/fpm/pool.d/"
sed -i "s/9999/99${version//./}/g" "/etc/php/${version}/fpm/pool.d/dummy.conf"
fi
fi
$BIN/v-restart-service "$v_php" "$restart"
@ -82,10 +82,10 @@ if [ -z "$version" ]; then
fi
done
else
if [ -f /etc/redhat-release ]; then
v_php="php$version-php-fpm"
if [ "$LOCAL_PHP" == "yes" ]; then
v_php="brepo-php-fpm$version"
else
v_php="php$version-fpm"
v_php="php$version-php-fpm"
fi
$BIN/v-restart-service "$v_php" "$restart"
if [ $? -ne 0 ]; then

@ -50,11 +50,22 @@ for webtpl_folder in $(ls $HESTIA_INSTALL_DIR/templates/web/* -d 2> /dev/null |
cp -rf "${webtpl_folder}" "${WEBTPL}/"
done
versions_list=$(ls -d /etc/opt/remi/php*)
for php_ver in $versions_list; do
[ ! -d "$php_ver/fpm/pool.d/" ] && continue
cp -f $HESTIA_INSTALL_DIR/php-fpm/multiphp.tpl ${WEBTPL}/php-fpm/PHP-${php_ver/\./_}.tpl
done
versions_list=""
if [ "$LOCAL_PHP" == "yes" ]; then
versions_list=$(ls -d /opt/brepo/php*)
for php_ver in $versions_list; do
[ ! -d "$php_ver/etc/php-fpm.d" ] && continue
vers=$(echo "$php_ver" | awk -F"/" '{ print $4 }' | sed "s/php\([[:digit:]]\+\)/\1/g")
cp -f $HESTIA_INSTALL_DIR/php-fpm/multiphp.tpl ${WEBTPL}/php-fpm/PHP-${vers/\./_}.tpl
done
else
versions_list=$(ls -d /etc/opt/remi/php*)
for php_ver in $versions_list; do
[ ! -d "$php_ver/php-fpm.d" ] && continue
vers=$(echo "$php_ver" | awk -F"/" '{ print $5 }' | sed "s/php\([[:digit:]]\+\)/\1/g")
cp -f $HESTIA_INSTALL_DIR/php-fpm/multiphp.tpl ${WEBTPL}/php-fpm/PHP-${vers/\./_}.tpl
done
fi
if [ -n "$awstats_patch" ]; then
# restore LoadPlugin variable

@ -101,34 +101,33 @@ is_web_alias_new() {
prepare_web_backend() {
# Accept first function argument as backend template otherwise fallback to $template global variable
local backend_template=${1:-$template}
if [ -f "/etc/redhat-release" ]; then
pool=$(find -L /etc/opt/remi/php80/ -name "$domain.conf" -exec dirname {} \; 2>/dev/null)
php_type=$(cat "$HESTIA/conf/hestia.conf" | grep "LOCAL_PHP" | grep "yes")
if [ -n "$php_type" ]; then
pool=$(find -L /opt/brepo/ -name "$domain.conf" -exec dirname {} \; 2>/dev/null)
else
pool=$(find -L /etc/php/ -name "$domain.conf" -exec dirname {} \;)
pool=$(find -L /etc/opt/remi/php80/ -name "$domain.conf" -exec dirname {} \; 2>/dev/null)
fi
# Check if multiple-PHP installed
if [ -f "/etc/redhat-release" ]; then
regex="^.*PHP-([0-9])([0-9])$"
else
regex="^.*PHP-([0-9])\_([0-9])$"
fi
regex="^.*PHP-([0-9])([0-9])$"
if [[ $backend_template =~ $regex ]]; then
if [ -f "/etc/redhat-release" ]; then
if [ -n "$php_type" ]; then
backend_version="${BASH_REMATCH[1]}${BASH_REMATCH[2]}"
pool=$(find -L /etc/opt/remi/php$backend_version -type d \( -name "pool.d" -o -name "*fpm.d" \))
pool=$(find -L /opt/brepo/php$backend_version -type d \( -name "pool.d" -o -name "*fpm.d" \))
else
backend_version="${BASH_REMATCH[1]}.${BASH_REMATCH[2]}"
pool=$(find -L /etc/php/$backend_version -type d \( -name "pool.d" -o -name "*fpm.d" \))
backend_version="${BASH_REMATCH[1]}${BASH_REMATCH[2]}"
pool=$(find -L /etc/opt/remi/php$backend_version -type d \( -name "pool.d" -o -name "*fpm.d" \))
fi
else
backend_version=$(multiphp_default_version)
if [ -z "$pool" ] || [ -z "$BACKEND" ]; then
if [ -f "/etc/redhat-release" ]; then
if [ -n "$php_type" ]; then
m_backend_version="${backend_version//./}"
pool=$(find -L /etc/opt/remi/php$m_backend_version -type d \( -name "pool.d" -o -name "*fpm.d" \))
pool=$(find -L /opt/brepo/php$m_backend_version -type d \( -name "pool.d" -o -name "*fpm.d" \))
else
pool=$(find -L /etc/php/$backend_version -type d \( -name "pool.d" -o -name "*fpm.d" \))
m_backend_version="${backend_version//./}"
pool=$(find -L /etc/opt/remi/php$m_backend_version -type d \( -name "pool.d" -o -name "*fpm.d" \))
fi
fi
fi
@ -151,11 +150,12 @@ prepare_web_backend() {
# Delete web backend
delete_web_backend() {
if [ -f "/etc/redhat-release" ]; then
find -L /etc/opt/remi/ -name "$backend_type.conf" -exec rm -f {} \;
else
find -L /etc/php/ -type f -name "$backend_type.conf" -exec rm -f {} \;
fi
php_type=$(cat "$HESTIA/conf/hestia.conf" | grep "LOCAL_PHP" | grep "yes")
if [ -n "$php_type" ]; then
find -L /opt/brepo/php* -name "$backend_type.conf" -exec rm -f {} \;
else
find -L /etc/opt/remi/ -name "$backend_type.conf" -exec rm -f {} \;
fi
}
# Prepare web aliases

@ -1561,9 +1561,16 @@ multiphp_count() {
multiphp_versions() {
local -a php_versions_list
local php_ver
local php_type_internal=$(cat "$HESTIA/conf/hestia.conf" | grep "LOCAL_PHP" | grep "yes")
local pool_internal=""
if [ "$(multiphp_count)" -gt 0 ]; then
for php_ver in $($BIN/v-list-sys-php plain); do
[ ! -d "/etc/php/$php_ver/fpm/pool.d/" ] && continue
if [ -n "$php_type_internal" ]; then
pool_internal="/opt/brepo/php$php_ver/etc/php-fpm.d"
else
pool_internal="/etc/opt/remi/php$php_ver/php-fpm.d"
fi
[ ! -d "$pool_internal" ] && continue
php_versions_list+=($php_ver)
done
echo "${php_versions_list[@]}"
@ -1572,11 +1579,19 @@ multiphp_versions() {
multiphp_default_version() {
# Get system wide default php version (set by update-alternatives)
local sys_phpversion=$(php -r "echo substr(phpversion(),0,3);")
local sys_phpversion_l=$(php -r "echo substr(phpversion(),0,3);")
local sys_phpversion="${sys_phpversion_l//./}"
local php_type_internal=$(cat "$HESTIA/conf/hestia.conf" | grep "LOCAL_PHP" | grep "yes")
local pool_internal=""
if [ -n "$php_type_internal" ]; then
pool_internal="/opt/brepo/php$sys_phpversion/etc/php-fpm.d"
else
pool_internal="/etc/opt/remi/php$sys_phpversion/php-fpm.d"
fi
# Check if the system php also has php-fpm enabled, otherwise return
# the most recent php version which does have it installed.
if [ ! -d "/etc/php/$sys_phpversion/fpm/pool.d/" ]; then
if [ ! -d "$pool_internal" ]; then
local all_versions="$(multiphp_versions)"
if [ -n "$all_versions" ]; then
sys_phpversion="${all_versions##*\ }"

Loading…
Cancel
Save