Skip to content

Commit

Permalink
Update PHP installer, Add PHP v8.4
Browse files Browse the repository at this point in the history
  • Loading branch information
joglomedia committed Jan 21, 2025
1 parent f5a1cac commit ea6796e
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 69 deletions.
51 changes: 26 additions & 25 deletions scripts/install_php.sh
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ function add_php_repo() {
# Install PHP and extensions.
##
function install_php() {
export PHP_IS_INSTALLED="no"
#local PHP_IS_INSTALLED="no"

# PHP version.
local PHPv="${1}"
Expand All @@ -95,8 +95,8 @@ function install_php() {

# Checking if PHP already installed.
if [[ -n $(command -v "php${PHPv}") && -n $(command -v "php-fpm${PHPv}") ]]; then
PHP_IS_INSTALLED="yes"
info "PHP ${PHPv} and it's extensions already exists."
#PHP_IS_INSTALLED="yes"
info "PHP ${PHPv} and it's extensions already exists, installation skipped."
else
echo "Preparing PHP ${PHPv} installation..."

Expand Down Expand Up @@ -127,10 +127,10 @@ function install_php() {

# Search extension from repository or PECL.
if apt-cache search "php${PHPv}-${EXT_NAME}" | grep -c "php${PHPv}-${EXT_NAME}" > /dev/null; then
echo "[php${PHPv}-${EXT_NAME}]"
echo "[php${PHPv}-${EXT_NAME}]"
PHP_REPO_EXTS+=("php${PHPv}-${EXT_NAME}")
elif apt-cache search "php-${EXT_NAME}" | grep -c "php-${EXT_NAME}" > /dev/null; then
echo "[php${PHPv}-${EXT_NAME}]"
echo "[php${PHPv}-${EXT_NAME}]"
PHP_REPO_EXTS+=("php-${EXT_NAME}")
else
# Fix PECL Sodium ext name.
Expand All @@ -140,7 +140,7 @@ function install_php() {

# Check PECL extension is available.
if curl -sLI "https://pecl.php.net/rest/r/${EXT_NAME}/allreleases.xml" | grep -q "HTTP/[.12]* [2].."; then
echo "[pecl-${EXT_NAME}]"
echo "[pecl-${EXT_NAME}]"
PHP_PECL_EXTS+=("${EXT_NAME}")

if [[ "${EXT_NAME}" == "openswoole" ]]; then
Expand Down Expand Up @@ -183,9 +183,6 @@ function install_php() {
success "PHP ${PHPv} along with ${TOTAL_EXTS} extensions installed."
fi

# Unset PHP extensions variables.
run unset PHP_EXTS PHP_REPO_EXTS PHP_PECL_EXTS PHP_PECL_FLAG

# Enable additional PHP extensions.
[[ "${INSTALL_MEMCACHED}" == true ]] && enable_php_memcached "${PHPv}"
[[ "${INSTALL_MONGODB}" == true ]] && enable_php_mongodb "${PHPv}"
Expand Down Expand Up @@ -389,7 +386,7 @@ EOL

# Enable FPM status.
run sed -i "/^;pm.status_path\ =.*/a pm.status_path\ =\ \/status" "/etc/php/${PHPv}/fpm/pool.d/www.conf"

# Enable chdir.
run sed -i "/^;chdir\ =.*/a chdir\ =\ \/usr\/share\/nginx\/html" "/etc/php/${PHPv}/fpm/pool.d/www.conf"

Expand Down Expand Up @@ -619,7 +616,7 @@ function enable_php_mongodb() {
PHPv=${DEFAULT_PHP_VERSION:-"8.3"}
fi

PHP_LIB_DIR=$("php-config${PHPv}" | grep -wE "\--extension-dir" | cut -d'[' -f2 | cut -d']' -f1)
PHP_LIB_DIR=$("php${PHPv}" -i | grep "extension_dir" | awk '{print $3}')
MONGODB_EXT_PATH="${PHP_LIB_DIR}/mongodb.so"

if [[ "${DRYRUN}" != true ]]; then
Expand Down Expand Up @@ -663,7 +660,7 @@ function enable_php_redis() {
PHPv=${DEFAULT_PHP_VERSION:-"8.3"}
fi

PHP_LIB_DIR=$("php-config${PHPv}" | grep -wE "\--extension-dir" | cut -d'[' -f2 | cut -d']' -f1)
PHP_LIB_DIR=$("php${PHPv}" -i | grep "extension_dir" | awk '{print $3}')
REDIS_EXT_PATH="${PHP_LIB_DIR}/redis.so"

if [[ "${DRYRUN}" != true ]]; then
Expand Down Expand Up @@ -1018,14 +1015,14 @@ function init_php_install() {
esac
done

# Include versions from config file.
read -r -a SELECTED_PHP_VERSIONS <<< "${PHP_VERSIONS}"

if [[ "${#OPT_PHP_VERSIONS[@]}" -gt 0 ]]; then
SELECTED_PHP_VERSIONS+=("${OPT_PHP_VERSIONS[@]}")
else
# Manually select PHP version in interactive mode.
if [[ "${AUTO_INSTALL}" != true ]]; then
if [[ "${AUTO_INSTALL}" == true ]]; then
# Include versions from config file.
read -r -a SELECTED_PHP_VERSIONS <<< "${PHP_VERSIONS}"
else
# Manually select PHP version in interactive mode.
echo "Which PHP version to be installed?"
echo "Available PHP versions:"
echo " 1). PHP 7.1 (EOL)"
Expand Down Expand Up @@ -1088,6 +1085,10 @@ function init_php_install() {
# Select all PHP versions (except EOL & Beta).
SELECTED_PHP_VERSIONS=("7.1" "7.2" "7.3" "7.4" "8.0" "8.1" "8.2" "8.3" "8.4")
;;
11 | n*)
info "No selected PHP version will be installed."
return
;;
*)
error "Your selected PHP version ${SELECTED_PHP} is not supported yet."
;;
Expand All @@ -1103,20 +1104,20 @@ function init_php_install() {
add_php_repo

# Install all selected PHP versions and extensions.
for PHPV in "${SELECTED_PHP_VERSIONS[@]}"; do
IS_PKG_AVAIL=$(apt-cache search "php${PHPV}" | grep -c "${PHPV}")
for PHPv in "${SELECTED_PHP_VERSIONS[@]}"; do
IS_PKG_AVAIL=$(apt-cache search "php${PHPv}" | grep -c "${PHPv}")

if [[ "${IS_PKG_AVAIL}" -gt 0 ]]; then
# Install PHP + default extensions.
if [[ -z $(command -v "php${PHPV}") ]]; then
install_php "${PHPV}"
install_php_loader "${PHPV}" "${OPT_PHP_LOADER}"
restart_php_fpm "${PHPV}"
if [[ -n $(command -v "php${PHPv}") && -n $(command -v "php-fpm${PHPv}") ]]; then
info "PHP version ${PHPv} and it's extensions already exists, installation skipped."
else
info "PHP version ${PHPV} and it's extensions already exists, installation skipped."
install_php "${PHPv}"
install_php_loader "${PHPv}" "${OPT_PHP_LOADER}"
restart_php_fpm "${PHPv}"
fi
else
error "PHP ${PHPV} package is not available for your operating system."
error "PHP ${PHPv} package is not available for your operating system."
fi
done

Expand Down
74 changes: 30 additions & 44 deletions scripts/remove_php.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ fi
##
# Remove PHP & FPM installation from system.
##
function remove_php_fpm() {
function remove_php() {
# PHP version.
local PHPv="${1}"
local REMOVED_PHP_LOADER="${2}"
Expand Down Expand Up @@ -253,27 +253,22 @@ function remove_php_loader() {
##
# Initialize PHP & FPM removal.
##
function init_php_fpm_removal() {
function init_php_removal() {
local REMOVED_PHP_VERSIONS=()
local OPT_PHP_VERSIONS=()
local OPT_PHP_LOADER=${PHP_LOADER:-"ioncube"}

OPTS=$(getopt -o p:l: \
-l php-version:,php-loader: \
-n "init_php_fpm_removal" -- "$@")
-n "init_php_removal" -- "$@")

eval set -- "${OPTS}"

while true; do
case "${1}" in
-p | --php-version)
shift
if [[ "${1}" == "all" ]]; then
# Include versions from config file.
read -r -a OPT_PHP_VERSIONS <<< "${PHP_VERSIONS}"
else
OPT_PHP_VERSIONS+=("${1}")
fi
OPT_PHP_VERSIONS+=("${1}")
shift
;;
-l | --php-loader)
Expand All @@ -292,14 +287,14 @@ function init_php_fpm_removal() {
esac
done

# Include versions from config file.
read -r -a REMOVED_PHP_VERSIONS <<< "${PHP_VERSIONS}"

if [[ "${#OPT_PHP_VERSIONS[@]}" -gt 0 ]]; then
REMOVED_PHP_VERSIONS+=("${OPT_PHP_VERSIONS[@]}")
else
# Manually select PHP version in interactive mode.
if [[ "${AUTO_REMOVE}" != true ]]; then
if [[ "${AUTO_REMOVE}" == true ]]; then
# Include versions from config file.
read -r -a REMOVED_PHP_VERSIONS <<< "${PHP_VERSIONS}"
else
# Manually select PHP version in interactive mode.
echo "Which PHP version to be removed?"
echo "Available PHP versions:"
echo " 1). PHP 7.1 (EOL)"
Expand Down Expand Up @@ -360,10 +355,10 @@ function init_php_fpm_removal() {
;;
10 | "all")
# Select all PHP versions (except EOL & Beta).
REMOVED_PHP_VERSIONS=("7.1" "7.2" "7.3" "7.4" "8.0" "8.1" "8.2" "8.3")
REMOVED_PHP_VERSIONS=("7.1" "7.2" "7.3" "7.4" "8.0" "8.1" "8.2" "8.3" "8.4")
;;
11 | n*)
info "No PHP version will be removed."
info "No selected PHP version will be removed."
return
;;
*)
Expand All @@ -374,11 +369,11 @@ function init_php_fpm_removal() {
fi

# If FORCE_REMOVE, then remove all installed PHP versions include the default.
if [[ "${FORCE_REMOVE}" == true ]]; then
#if [[ "${FORCE_REMOVE}" == true ]]; then
# Also remove default LEMPer PHP.
DEFAULT_PHP_VERSION=${DEFAULT_PHP_VERSION:-"8.3"}
REMOVED_PHP_VERSIONS+=("${DEFAULT_PHP_VERSION}")
fi
# DEFAULT_PHP_VERSION=${DEFAULT_PHP_VERSION:-"8.3"}
# REMOVED_PHP_VERSIONS+=("${DEFAULT_PHP_VERSION}")
#fi

# Remove all selected PHP versions.
if [[ "${#REMOVED_PHP_VERSIONS[@]}" -gt 0 ]]; then
Expand All @@ -387,7 +382,11 @@ function init_php_fpm_removal() {
REMOVED_PHP_VERSIONS=($(printf "%s\n" "${REMOVED_PHP_VERSIONS[@]}" | sort -u | tr '\n' ' '))

for PHP_VER in "${REMOVED_PHP_VERSIONS[@]}"; do
remove_php_fpm "${PHP_VER}" "${OPT_PHP_LOADER}"
if [[ -n $(command -v "php${PHPv}") && -n $(command -v "php-fpm${PHPv}") ]]; then
remove_php "${PHP_VER}" "${OPT_PHP_LOADER}"
else
info "PHP ${PHPv} packages installation not found, uninstall skipped."
fi
done

# Final clean up (executed only if no PHP version installed).
Expand Down Expand Up @@ -439,29 +438,16 @@ function init_php_fpm_removal() {

echo "Uninstalling PHP packages..."

if [[ -n $(command -v php7.1) || \
-n $(command -v php7.2) || \
-n $(command -v php7.3) || \
-n $(command -v php7.4) || \
-n $(command -v php8.0) || \
-n $(command -v php8.1) || \
-n $(command -v php8.2) || \
-n $(command -v php8.3) || \
-n $(command -v php8.4)
]]; then
if [[ "${AUTO_REMOVE}" == true ]]; then
REMOVE_PHP="y"
else
while [[ "${REMOVE_PHP}" != "y" && "${REMOVE_PHP}" != "n" ]]; do
read -rp "Are you sure to remove PHP package? [y/n]: " -e REMOVE_PHP
done
fi
if [[ "${AUTO_REMOVE}" == true ]]; then
REMOVE_PHP="y"
else
while [[ "${REMOVE_PHP}" != "y" && "${REMOVE_PHP}" != "n" ]]; do
read -rp "Are you sure to remove PHP package? [y/n]: " -e REMOVE_PHP
done
fi

if [[ "${REMOVE_PHP}" == Y* || "${REMOVE_PHP}" == y* ]]; then
init_php_fpm_removal "$@"
else
echo "Found PHP packages, but not removed."
fi
if [[ "${REMOVE_PHP}" == Y* || "${REMOVE_PHP}" == y* ]]; then
init_php_removal "$@"
else
info "Oops, PHP packages installation not found."
echo "PHP packages uninstallation skipped."
fi

0 comments on commit ea6796e

Please sign in to comment.