From fc60cd0a57bc0c06cd912230818cd4fc474ef3f6 Mon Sep 17 00:00:00 2001 From: Edi Septriyanto Date: Sat, 18 Dec 2021 10:38:11 +0700 Subject: [PATCH] Move PHP loader installation to PHP installer file --- .env.dist | 5 +- install.sh | 18 +- scripts/install_php.sh | 347 ++++++++++++++++++++++----- scripts/install_phploader.sh | 444 ----------------------------------- scripts/remove_php.sh | 249 ++++++++++++++++---- scripts/remove_phploader.sh | 327 -------------------------- 6 files changed, 499 insertions(+), 891 deletions(-) delete mode 100755 scripts/install_phploader.sh delete mode 100755 scripts/remove_phploader.sh diff --git a/.env.dist b/.env.dist index 94c65f1..a95fa2c 100644 --- a/.env.dist +++ b/.env.dist @@ -164,9 +164,8 @@ DEFAULT_PHP_VERSION="7.4" # to load protected and encoded files. INSTALL_PHP_LOADER=false -# Available PHP loader: ioncube | sourceguardian -# leave it blank or "none" to skip PHP loader installation. -PHP_LOADER="none" +# Available PHP loader: ioncube | sourceguardian | all +PHP_LOADER="ioncube" [php-phalcon] # Phalcon is a PHP web framework based on the MVC pattern delivered as C-extension. diff --git a/install.sh b/install.sh index 73807d8..a12c091 100755 --- a/install.sh +++ b/install.sh @@ -103,18 +103,6 @@ if [ -f ./scripts/install_php.sh ]; then . ./scripts/install_php.sh fi -### Phalcon PHP installation ### -if [ -f ./scripts/install_phalcon.sh ]; then - echo "" - . ./scripts/install_phalcon.sh -fi - -### Phalcon PHP installation ### -if [ -f ./scripts/install_phploader.sh ]; then - echo "" - . ./scripts/install_phploader.sh -fi - ### Imagick installation ### if [ -f ./scripts/install_imagemagick.sh ]; then echo "" @@ -127,6 +115,12 @@ if [ -f ./scripts/install_memcached.sh ]; then . ./scripts/install_memcached.sh fi +### Phalcon PHP installation ### +if [ -f ./scripts/install_phalcon.sh ]; then + echo "" + . ./scripts/install_phalcon.sh +fi + ### MySQL database installation ### if [ -f ./scripts/install_mariadb.sh ]; then echo "" diff --git a/scripts/install_php.sh b/scripts/install_php.sh index 6047313..e943ce0 100755 --- a/scripts/install_php.sh +++ b/scripts/install_php.sh @@ -56,9 +56,9 @@ function add_php_repo() { } ## -# Install PHP & FPM package. +# Install PHP and extensions. ## -function install_php_fpm() { +function install_php() { export PHP_IS_INSTALLED="no" # PHP version. @@ -70,7 +70,7 @@ function install_php_fpm() { # Checking if PHP already installed. if [[ -n $(command -v "php${PHPv}") ]]; then PHP_IS_INSTALLED="yes" - info "PHP ${PHPv} and it's extensions already exists, installation skipped." + info "PHP ${PHPv} and it's extensions already exists." else echo "Installing PHP ${PHPv} and required extensions..." @@ -170,11 +170,40 @@ function install_php_fpm() { run mkdir -p /var/log/php fi - # Optimize PHP configuration. + # Optimize PHP & FPM configuration. optimize_php_fpm "${PHPv}" fi } +## +# Restart PHP-FPM service. +## +function restart_php_fpm() { + # PHP version. + local PHPv="${1}" + if [[ -z "${PHPv}" ]]; then + PHPv=${DEFAULT_PHP_VERSION:-"7.4"} + fi + + # Restart PHP-FPM service. + if [[ "${DRYRUN}" != true ]]; then + if [[ $(pgrep -c "php-fpm${PHPv}") -gt 0 ]]; then + run systemctl reload "php${PHPv}-fpm" + success "php${PHPv}-fpm reloaded successfully." + elif [[ -n $(command -v "php${PHPv}") ]]; then + run systemctl start "php${PHPv}-fpm" + + if [[ $(pgrep -c "php-fpm${PHPv}") -gt 0 ]]; then + success "php${PHPv}-fpm started successfully." + else + error "Something goes wrong with PHP ${PHPv} & FPM installation." + fi + fi + else + info "php${PHPv}-fpm reloaded in dry run mode." + fi +} + ## # PHP & FPM Optimization. ## @@ -393,24 +422,6 @@ EOL # Fix cgi.fix_pathinfo (for PHP older than 5.3). #sed -i "s/cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/g" /etc/php/${PHPv}/fpm/php.ini - - # Restart PHP-fpm server. - if [[ "${DRYRUN}" == true ]]; then - info "php${PHPv}-fpm reloaded in dry run mode." - else - if [[ $(pgrep -c "php-fpm${PHPv}") -gt 0 ]]; then - run systemctl reload "php${PHPv}-fpm" - success "php${PHPv}-fpm reloaded successfully." - elif [[ -n $(command -v "php${PHPv}") ]]; then - run systemctl start "php${PHPv}-fpm" - - if [[ $(pgrep -c "php-fpm${PHPv}") -gt 0 ]]; then - success "php${PHPv}-fpm started successfully." - else - error "Something goes wrong with PHP ${PHPv} & FPM installation." - fi - fi - fi } ## @@ -563,25 +574,8 @@ session.bak_handler="memcache" session.bak_path="tcp://127.0.0.1:11211" EOL - success "PHP ${PHPv} Memcache module enabled." + success "PHP ${PHPv} Memcached extension enabled." fi - - # Reload PHP-FPM service. - echo "Restarting php${PHPv}-fpm to apply Memcached module." - - if [[ $(pgrep -c "php-fpm${PHPv}") -gt 0 ]]; then - run systemctl reload "php${PHPv}-fpm" - success "php${PHPv}-fpm restarted successfully." - elif [[ -n $(command -v "php${PHPv}") ]]; then - run systemctl start "php${PHPv}-fpm" - - if [[ $(pgrep -c "php-fpm${PHPv}") -gt 0 ]]; then - success "php${PHPv}-fpm started successfully." - else - info "Something went wrong with php${PHPv}-fpm installation." - fi - fi - else info "It seems that PHP ${PHPv} not yet installed. Please install it before!" fi @@ -591,25 +585,253 @@ EOL } ## -# Initialize PHP & FPM Installation. +# Install ionCube Loader. ## -function init_php_fpm_install() { +function install_ioncube_loader() { + echo "Installing ionCube PHP loader..." + + # Delete old loaders file. + if [ -d /usr/lib/php/loaders/ioncube ]; then + echo "Remove old/existing ionCube PHP loader." + run rm -fr /usr/lib/php/loaders/ioncube + fi + + local CURRENT_DIR && CURRENT_DIR=$(pwd) + run cd "${BUILD_DIR}" || return 1 + + echo "Downloading latest ionCube PHP loader..." + + ARCH=${ARCH:-$(uname -p)} + + if [[ "${ARCH}" == "x86_64" ]]; then + run wget -q --show-progress "https://downloads2.ioncube.com/loader_downloads/ioncube_loaders_lin_x86-64.tar.gz" + run tar -xzf ioncube_loaders_lin_x86-64.tar.gz + run rm -f ioncube_loaders_lin_x86-64.tar.gz + else + run wget -q --show-progress "https://downloads2.ioncube.com/loader_downloads/ioncube_loaders_lin_x86.tar.gz" + run tar -xzf ioncube_loaders_lin_x86.tar.gz + run rm -f ioncube_loaders_lin_x86.tar.gz + fi + + run mv -f ioncube /usr/lib/php/loaders/ + run cd "${CURRENT_DIR}" || return 1 +} + +## +# Enable ionCube Loader. +## +function enable_ioncube_loader() { + # PHP version. + local PHPv="${1}" + if [ -z "${PHPv}" ]; then + PHPv=${DEFAULT_PHP_VERSION:-"7.4"} + fi + + echo "Enable ionCube PHP ${PHPv} loader." + + if [[ "${DRYRUN}" != true ]]; then + if [[ -f "/usr/lib/php/loaders/ioncube/ioncube_loader_lin_${PHPv}.so" && -n $(command -v "php${PHPv}") ]]; then + cat > "/etc/php/${PHPv}/mods-available/ioncube.ini" < "/etc/php/${PHPv}/mods-available/sourceguardian.ini" </dev/null 2>&1 && pwd ) - # shellcheck disable=SC1091 - . "${BASE_DIR}/helper.sh" -fi - -# Make sure only root can run this installer script. -requires_root - -# Make sure only supported distribution can run this installer script. -preflight_system_check - -## -# Install ionCube Loader. -# -function install_ioncube() { - echo "Installing ionCube PHP loader..." - - # Delete old loaders file. - if [ -d /usr/lib/php/loaders/ioncube ]; then - echo "Removing old/existing ionCube PHP loader..." - run rm -fr /usr/lib/php/loaders/ioncube - fi - - local CURRENT_DIR && CURRENT_DIR=$(pwd) - run cd "${BUILD_DIR}" || return 1 - - echo "Download latest ionCube PHP loader..." - - ARCH=${ARCH:-$(uname -p)} - if [[ "${ARCH}" == "x86_64" ]]; then - run wget -q "https://downloads2.ioncube.com/loader_downloads/ioncube_loaders_lin_x86-64.tar.gz" - run tar -xzf ioncube_loaders_lin_x86-64.tar.gz - run rm -f ioncube_loaders_lin_x86-64.tar.gz - else - run wget -q "https://downloads2.ioncube.com/loader_downloads/ioncube_loaders_lin_x86.tar.gz" - run tar -xzf ioncube_loaders_lin_x86.tar.gz - run rm -f ioncube_loaders_lin_x86.tar.gz - fi - - run mv -f ioncube /usr/lib/php/loaders/ - run cd "${CURRENT_DIR}" || return 1 -} - -## -# Enable ionCube Loader. -# -function enable_ioncube() { - # PHP version. - local PHPv="${1}" - if [ -z "${PHPv}" ]; then - PHPv=${PHP_VERSION:-"7.4"} - fi - - echo "Enable ionCube PHP ${PHPv} loader" - - if [[ "${DRYRUN}" == true ]]; then - info "ionCube PHP ${PHPv} enabled in dry run mode." - else - if [[ -f "/usr/lib/php/loaders/ioncube/ioncube_loader_lin_${PHPv}.so" && -n $(command -v "php${PHPv}") ]]; then - cat > "/etc/php/${PHPv}/mods-available/ioncube.ini" < "/etc/php/${PHPv}/mods-available/sourceguardian.ini" </dev/null 2>&1 && pwd ) - # shellcheck disable=SC1091 - . "${BASE_DIR}/helper.sh" -fi - -# Make sure only root can run this installer script. -requires_root - -## -# Disable ionCube Loader. -# -function disable_ioncube() { - # PHP version. - local PHPv="${1}" - if [ -z "${PHPv}" ]; then - PHPv=${PHP_VERSION:-"7.3"} - fi - - echo "Disabling ionCube PHP ${PHPv} loader" - - run unlink "/etc/php/${PHPv}/fpm/conf.d/05-ioncube.ini" - run unlink "/etc/php/${PHPv}/cli/conf.d/05-ioncube.ini" -} - -## -# Remove ionCube Loader. -# -function remove_ioncube() { - # PHP version. - local PHPv="${1}" - if [ -z "${PHPv}" ]; then - PHPv=${PHP_VERSION:-"7.3"} - fi - - echo "Uninstalling ionCube PHP ${PHPv} loader..." - - if [[ -f "/etc/php/${PHPv}/fpm/conf.d/05-ioncube.ini" || \ - -f "/etc/php/${PHPv}/cli/conf.d/05-ioncube.ini" ]]; then - disable_ioncube "${PHPv}" - fi - - if [ -d /usr/lib/php/loaders/ioncube ]; then - run rm -fr /usr/lib/php/loaders/ioncube - success "ionCube PHP ${PHPv} loader has been removed." - else - info "ionCube PHP ${PHPv} loader couldn't be found." - fi -} - -## -# Disable SourceGuardian Loader. -# -function disable_sourceguardian() { - # PHP version. - local PHPv="${1}" - if [ -z "${PHPv}" ]; then - PHPv=${PHP_VERSION:-"7.3"} - fi - - echo "Disabling SourceGuardian PHP ${PHPv} loader" - - run unlink "/etc/php/${PHPv}/fpm/conf.d/05-sourceguardian.ini" - run unlink "/etc/php/${PHPv}/cli/conf.d/05-sourceguardian.ini" -} - -## -# Remove SourceGuardian Loader. -# -function remove_sourceguardian() { - # PHP version. - local PHPv="${1}" - if [ -z "${PHPv}" ]; then - PHPv=${PHP_VERSION:-"7.3"} - fi - - echo "Uninstalling SourceGuardian PHP ${PHPv} loader..." - - if [[ -f "/etc/php/${PHPv}/fpm/conf.d/05-sourceguardian.ini" || \ - -f "/etc/php/${PHPv}/cli/conf.d/05-sourceguardian.ini" ]]; then - disable_sourceguardian "${PHPv}" - fi - - if [ -d /usr/lib/php/loaders/sourceguardian ]; then - run rm -fr /usr/lib/php/loaders/sourceguardian - success "SourceGuardian PHP ${PHPv} loader has been removed." - else - info "SourceGuardian PHP ${PHPv} loader couldn't be found." - fi -} - -## -# Initialize PHP Loader removal. -# -function init_phploader_removal() { - local SELECTED_PHP="" - local SELECTED_PHPLOADER="" - - OPTS=$(getopt -o p:l:ir \ - -l php-version:,loader:,install,remove \ - -n "init_phploader_install" -- "$@") - - eval set -- "${OPTS}" - - while true - do - case "${1}" in - -p|--php-version) shift - SELECTED_PHP="${1}" - shift - ;; - -l|--loader) shift - SELECTED_PHPLOADER="${1}" - shift - ;; - -i|--install) shift - #ACTION="install" - ;; - -r|--remove) shift - #ACTION="remove" - ;; - --) shift - break - ;; - *) - fail "Invalid argument: ${1}" - exit 1 - ;; - esac - done - - if [[ "${AUTO_INSTALL}" == true ]]; then - if [ -z "${SELECTED_PHP}" ]; then - SELECTED_PHP=${PHP_VERSION:-"7.3"} - fi - else - echo "Which version of PHP to be installed?" - echo "Supported PHP version:" - echo " 1). PHP 5.6 (EOL)" - echo " 2). PHP 7.0 (EOL)" - echo " 3). PHP 7.1 (SFO)" - echo " 4). PHP 7.2 (Stable)" - echo " 5). PHP 7.3 (Latest stable)" - echo " 6). PHP 7.4 (Beta)" - echo " 7). All available versions" - echo "+--------------------------------------+" - - while [[ ${SELECTED_PHP} != "1" && ${SELECTED_PHP} != "2" && ${SELECTED_PHP} != "3" && \ - ${SELECTED_PHP} != "4" && ${SELECTED_PHP} != "5" && ${SELECTED_PHP} != "6" && \ - ${SELECTED_PHP} != "7" && ${SELECTED_PHP} != "5.6" && ${SELECTED_PHP} != "7.0" && \ - ${SELECTED_PHP} != "7.1" && ${SELECTED_PHP} != "7.2" && ${SELECTED_PHP} != "7.3" && \ - ${SELECTED_PHP} != "7.4" && ${SELECTED_PHP} != "all" - ]]; do - read -rp "Select a PHP version or an option [1-7]: " -e SELECTED_PHP - done - fi - - local PHPv - case ${SELECTED_PHP} in - 1|"5.6") - PHPv="5.6" - ;; - 2|"7.0") - PHPv="7.0" - ;; - 3|"7.1") - PHPv="7.1" - ;; - 4|"7.2") - PHPv="7.2" - ;; - 5|"7.3") - PHPv="7.3" - ;; - 6|"7.4") - PHPv="7.4" - ;; - 7|"all") - # Install all PHP version (except EOL & Beta). - PHPv="all" - ;; - *) - PHPv="unsupported" - error "Your selected PHP version ${SELECTED_PHP} is not supported." - ;; - esac - - # Install PHP loader. - if [[ "${PHPv}" != "unsupported" && ! $(version_older_than "${PHPv}" "5.6") ]]; then - if [[ "${AUTO_INSTALL}" == true ]]; then - # PHP Loader. - if [ -z "${SELECTED_PHPLOADER}" ]; then - SELECTED_PHPLOADER=${PHP_LOADER:-""} - fi - - if [[ -z "${SELECTED_PHPLOADER}" || "${SELECTED_PHPLOADER}" == "none" ]]; then - INSTALL_PHPLOADER="n" - else - INSTALL_PHPLOADER="y" - fi - else - while [[ "${INSTALL_PHPLOADER}" != "y" && "${INSTALL_PHPLOADER}" != "n" ]]; do - read -rp "Do you want to remove PHP Loaders? [y/n]: " -i n -e INSTALL_PHPLOADER - done - fi - - if [[ ${INSTALL_PHPLOADER} == Y* || ${INSTALL_PHPLOADER} == y* ]]; then - if ! "${AUTO_INSTALL}"; then - echo "" - echo "Available PHP Loaders:" - echo " 1). ionCube Loader (latest stable)" - echo " 2). SourceGuardian (latest stable)" - echo " 3). All loaders (ionCube, SourceGuardian)" - echo "--------------------------------------------" - - while [[ ${SELECTED_PHPLOADER} != "1" && ${SELECTED_PHPLOADER} != "2" && \ - ${SELECTED_PHPLOADER} != "3" && ${SELECTED_PHPLOADER} != "ioncube" && \ - ${SELECTED_PHPLOADER} != "sg" && ${SELECTED_PHPLOADER} != "ic" && \ - ${SELECTED_PHPLOADER} != "sourceguardian" && ${SELECTED_PHPLOADER} != "all" - ]]; do - read -rp "Select an option [1-3]: " -i "${PHP_LOADER}" -e SELECTED_PHPLOADER - done - fi - - # Create loaders directory - if [ ! -d /usr/lib/php/loaders ]; then - run mkdir -p /usr/lib/php/loaders - fi - - case ${SELECTED_PHPLOADER} in - 1|"ic"|"ioncube") - install_ioncube - - if [ "${PHPv}" != "all" ]; then - enable_ioncube "${PHPv}" - - # Required for LEMPer default PHP. - if [[ "${PHPv}" != "7.3" && -n $(command -v "php${DEFAULT_PHP_VERSION}") ]]; then - enable_ioncube "7.3" - fi - else - # Install all PHP version (except EOL & Beta). - enable_ioncube "5.6" - enable_ioncube "7.0" - enable_ioncube "7.1" - enable_ioncube "7.2" - enable_ioncube "7.3" - enable_ioncube "7.4" - fi - ;; - - 2|"sg"|"sourceguardian") - install_sourceguardian - - if [[ "${PHPv}" != "all" ]]; then - enable_sourceguardian "${PHPv}" - - # Required for LEMPer default PHP. - if [[ "${PHPv}" != "7.3" && -n $(command -v php7.3) ]]; then - enable_sourceguardian "7.3" - fi - else - # Install all PHP version (except EOL & Beta). - enable_sourceguardian "5.6" - enable_sourceguardian "7.0" - enable_sourceguardian "7.1" - enable_sourceguardian "7.2" - enable_sourceguardian "7.3" - enable_sourceguardian "7.4" - fi - ;; - - "all") - install_ioncube - install_sourceguardian - - if [ "${PHPv}" != "all" ]; then - enable_ioncube "${PHPv}" - enable_sourceguardian "${PHPv}" - - # Required for LEMPer default PHP - if [[ "${PHPv}" != "7.3" && -n $(command -v php7.3) ]]; then - enable_ioncube "7.3" - enable_sourceguardian "7.3" - fi - else - # Install all PHP version (except EOL & Beta). - enable_ioncube "5.6" - enable_ioncube "7.0" - enable_ioncube "7.1" - enable_ioncube "7.2" - enable_ioncube "7.3" - enable_ioncube "7.4" - - enable_sourceguardian "5.6" - enable_sourceguardian "7.0" - enable_sourceguardian "7.1" - enable_sourceguardian "7.2" - enable_sourceguardian "7.3" - enable_sourceguardian "7.4" - fi - ;; - - *) - info "Your selected PHP loader ${SELECTED_PHPLOADER} is not supported yet." - ;; - esac - else - info "${SELECTED_PHPLOADER^} PHP ${PHPv} loader installation skipped." - fi - fi -} - -echo "Uninstalling PHP Loader..." - -# Start running things from a call at the end so if this script is executed -# after a partial download it doesn't do anything. -init_phploader_removal "$@"