From 4f9abaa78a0d6536e176844f13f15522cde1045d Mon Sep 17 00:00:00 2001 From: Edi Septriyanto Date: Sat, 11 Dec 2021 22:31:21 +0700 Subject: [PATCH] Improved PHP installation --- scripts/install_phalcon.sh | 30 +++++---- scripts/install_php.sh | 119 ++++++++++++++++++++++++++++++++++- scripts/install_phploader.sh | 72 +++++++-------------- 3 files changed, 156 insertions(+), 65 deletions(-) diff --git a/scripts/install_phalcon.sh b/scripts/install_phalcon.sh index 837bf7e..e62e76c 100755 --- a/scripts/install_phalcon.sh +++ b/scripts/install_phalcon.sh @@ -1,16 +1,16 @@ #!/usr/bin/env bash # Phalcon & Zephir Installer -# Min. Requirement : GNU/Linux Ubuntu 16.04 -# Last Build : 02/11/2019 +# Min. Requirement : GNU/Linux Ubuntu 18.04 +# Last Build : 11/12/2021 # Author : MasEDI.Net (me@masedi.net) # Since Version : 1.2.0 # Include helper functions. -if [ "$(type -t run)" != "function" ]; then - BASEDIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd ) +if [[ "$(type -t run)" != "function" ]]; then + BASE_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd ) # shellcheck disable=SC1091 - . "${BASEDIR}/helper.sh" + . "${BASE_DIR}/helper.sh" fi # Make sure only root can run this installer script. @@ -33,7 +33,7 @@ function install_phalcon() { run cd "${BUILD_DIR}" || return 1 # Install Zephir from source. - if "${AUTO_INSTALL}"; then + if [[ "${AUTO_INSTALL}" == true ]]; then if [[ ${INSTALL_PHP_ZEPHIR} == y* || ${INSTALL_PHP_ZEPHIR} == true ]]; then DO_INSTALL_ZEPHIR="y" else @@ -182,10 +182,13 @@ EOL # Enable Phalcon extension. function enable_phalcon() { # PHP version. - local PHPv=${1} + local PHPv="${1}" + if [[ -z "${PHPv}" ]]; then + PHPv=${DEFAULT_PHP_VERSION:-"7.4"} + fi - if "${DRYRUN}"; then - echo "Enabling Phalcon PHP ${PHPv} extension in dryrun mode." + if [[ "${DRYRUN}" == true ]]; then + echo "Enabling Phalcon PHP ${PHPv} extension in dry run mode." else # Optimize Phalcon PHP extension. if [ -d "/etc/php/${PHPv}/mods-available/" ]; then @@ -305,7 +308,7 @@ function init_phalcon_install() { # Check if PHP version DO_INSTALL_PHALCON="n". DO_INSTALL_PHALCON="n" - if "${AUTO_INSTALL}"; then + if [[ "${AUTO_INSTALL}" == true ]]; then if [[ -z "${PHP_PHALCON_INSTALLER}" || "${PHP_PHALCON_INSTALLER}" == "none" ]]; then DO_INSTALL_PHALCON="n" else @@ -326,7 +329,7 @@ function init_phalcon_install() { if [[ ${DO_INSTALL_PHALCON} == y* && ${INSTALL_PHP_PHALCON} == true ]]; then # Select installer. - if "${AUTO_INSTALL}"; then + if [[ "${AUTO_INSTALL}" == true ]]; then if [ -z "${PHALCON_INSTALLER}" ]; then SELECTED_INSTALLER=${PHP_PHALCON_INSTALLER} fi @@ -346,7 +349,7 @@ function init_phalcon_install() { fi # Select Phalcon version. - if "${AUTO_INSTALL}"; then + if [[ "${AUTO_INSTALL}" == true ]]; then if [ -z "${SELECTED_PHALCON}" ]; then SELECTED_PHALCON=${PHP_PHALCON_VERSION} fi @@ -387,7 +390,7 @@ function init_phalcon_install() { esac # Select PHP version. - if "${AUTO_INSTALL}"; then + if [[ "${AUTO_INSTALL}" == true ]]; then if [ -z "${SELECTED_PHP}" ]; then SELECTED_PHP=${PHP_VERSION} fi @@ -449,6 +452,7 @@ function init_phalcon_install() { local SUPPORTED_PHP local PHP_PHALCON_PKG + if version_older_than "${PHALCON_VERSION}" "3.4.6"; then SUPPORTED_PHP="5.6 7.0 7.1" PHP_PHALCON_PKG="php-phalcon3" diff --git a/scripts/install_php.sh b/scripts/install_php.sh index 73c658e..c4d204b 100755 --- a/scripts/install_php.sh +++ b/scripts/install_php.sh @@ -458,6 +458,117 @@ function install_php_composer() { fi } +## +# Install PHP MongoDB extension. +## +function install_php_mongodb() { + # PHP version. + local PHPv="${1}" + if [[ -z "${PHPv}" ]]; then + PHPv=${DEFAULT_PHP_VERSION:-"7.4"} + fi + + echo -e "\nInstalling PHP ${PHPv} MongoDB extension..." + + run apt-get install -qq -y "php${PHPv}-mongodb" + + local CURRENT_DIR && \ + CURRENT_DIR=$(pwd) + + run cd "${BUILD_DIR}" || return 1 + run git clone --depth=1 -q https://github.com/mongodb/mongo-php-driver.git && \ + run cd mongo-php-driver && \ + run git submodule update --init + + if [[ -n $(command -v "php${PHPv}") ]]; then + run "/usr/bin/phpize${PHPv}" && \ + run ./configure --with-php-config="/usr/bin/php-config${PHPv}" + else + run /usr/bin/phpize && \ + run ./configure + fi + + run make all && \ + run make install + + PHP_LIB_DIR=$("php-config${PHPv}" | grep -wE "\--extension-dir" | cut -d'[' -f2 | cut -d']' -f1) + + if [ -f "${PHP_LIB_DIR}/mongodb.so" ]; then + success "MongoDB module sucessfully installed at ${PHP_LIB_DIR}/mongodb.so." + run chmod 0644 "${PHP_LIB_DIR}/mongodb.so" + fi + + run cd "${CURRENT_DIR}" || return 1 +} + +## +# Install PHP Memcached extension. +## +function install_php_memcached() { + # PHP version. + local PHPv="${1}" + if [[ -z "${PHPv}" ]]; then + PHPv=${DEFAULT_PHP_VERSION:-"7.4"} + fi + + # Install PHP memcached module. + echo "Installing PHP ${PHPv} memcached extension..." + + if [[ "${DRYRUN}" != true ]]; then + run apt-get install -qq -y "php${PHPv}-igbinary" "php${PHPv}-memcache" \ + "php${PHPv}-memcached" "php${PHPv}-msgpack" + else + info "PHP ${PHPv} Memcached extension installed in dry run mode." + fi + + echo "Optimizing PHP ${PHPv} memcached extension..." + + # Optimize PHP memcache extension. + if [[ "${DRYRUN}" != true ]]; then + if [ -d "/etc/php/${PHPv}/mods-available/" ]; then + if [ -f "/etc/php/${PHPv}/mods-available/memcache.ini" ]; then + cat >> "/etc/php/${PHPv}/mods-available/memcache.ini" </dev/null 2>&1 && pwd ) +if [[ "$(type -t run)" != "function" ]]; then + BASE_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd ) # shellcheck disable=SC1091 - . "${BASEDIR}/helper.sh" + . "${BASE_DIR}/helper.sh" fi # Make sure only root can run this installer script. @@ -60,8 +60,8 @@ function enable_ioncube() { echo "Enable ionCube PHP ${PHPv} loader" - if "${DRYRUN}"; then - info "ionCube PHP ${PHPv} enabled in dryrun mode." + 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" <