Improved PHP installation

This commit is contained in:
Edi Septriyanto
2021-12-11 22:31:21 +07:00
parent cd85217e10
commit 4f9abaa78a
3 changed files with 156 additions and 65 deletions

View File

@@ -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"

View File

@@ -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" <<EOL
; Optimized for LEMPer stack.
memcache.dbpath="/var/lib/memcache"
memcache.maxreclevel=0
memcache.maxfiles=0
memcache.archivememlim=0
memcache.maxfilesize=0
memcache.maxratio=0
; Custom setting for WordPress + W3TC.
session.bak_handler="memcache"
session.bak_path="tcp://127.0.0.1:11211"
EOL
success "PHP ${PHPv} Memcache module 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
else
info "PHP ${PHPv} Memcached extension optimized in dry run mode."
fi
}
##
# Initialize PHP & FPM Installation.
##
@@ -572,11 +683,14 @@ function init_php_fpm_install() {
# Add Ondrej's PHP repository.
add_php_repo
# Install all selected PHP versions.
# Install all selected PHP versions and extensions.
for VERSION in "${SELECTED_PHP_VERSIONS[@]}"; do
IS_PKG_AVAIL=$(apt-cache search "php${VERSION}" | grep -c "${VERSION}")
if [[ "${IS_PKG_AVAIL}" -gt 0 ]]; then
# Install PHP + default extensions.
install_php_fpm "${VERSION}"
[[ "${INSTALL_MEMCACHED}" == true ]] && install_php_memcached "${VERSION}"
[[ "${INSTALL_MONGODB}" == true ]] && install_php_mongodb "${VERSION}"
else
error "PHP ${VERSION} package is not available on your operating system."
fi
@@ -586,7 +700,10 @@ function init_php_fpm_install() {
if [[ -z $(command -v "php${DEFAULT_PHP_VERSION}") ]]; then
info "LEMPer requires PHP ${DEFAULT_PHP_VERSION} as default to run its administration tool."
echo "PHP ${DEFAULT_PHP_VERSION} now being installed..."
install_php_fpm "${DEFAULT_PHP_VERSION}"
[[ "${INSTALL_MEMCACHED}" == true ]] && install_php_memcached "${DEFAULT_PHP_VERSION}"
[[ "${INSTALL_MONGODB}" == true ]] && install_php_mongodb "${DEFAULT_PHP_VERSION}"
fi
# Install PHP composer.

View File

@@ -1,16 +1,16 @@
#!/usr/bin/env bash
# PHP Loader Installer
# Min. Requirement : GNU/Linux Ubuntu 16.04 & 16.04
# Last Build : 03/04/2021
# Min. Requirement : GNU/Linux Ubuntu 18.04
# Last Build : 11/12/2021
# Author : MasEDI.Net (me@masedi.net)
# Since Version : 1.3.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.
@@ -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" <<EOL
@@ -79,7 +79,7 @@ EOL
fi
# Restart PHP-fpm server.
if "${DRYRUN}"; then
if [[ "${DRYRUN}" == true ]]; then
info "php${PHPv}-fpm reloaded in dry run mode."
else
if [[ $(pgrep -c "php-fpm${PHPv}") -gt 0 ]]; then
@@ -123,8 +123,8 @@ function disable_ioncube() {
function remove_ioncube() {
# PHP version.
local PHPv="${1}"
if [ -z "${PHPv}" ]; then
PHPv=${PHP_VERSION:-"7.4"}
if [[ -z "${PHPv}" ]]; then
PHPv=${DEFAULT_PHP_VERSION:-"7.4"}
fi
echo "Uninstalling ionCube PHP ${PHPv} loader..."
@@ -184,14 +184,14 @@ function install_sourceguardian() {
function enable_sourceguardian() {
# PHP version.
local PHPv="${1}"
if [ -z "${PHPv}" ]; then
PHPv=${PHP_VERSION:-"7.4"}
if [[ -z "${PHPv}" ]]; then
PHPv=${DEFAULT_PHP_VERSION:-"7.4"}
fi
echo "Enable SourceGuardian PHP ${PHPv} loader..."
if "${DRYRUN}"; then
info "SourceGuardian PHP ${PHPv} enabled in dryrun mode."
if [[ "${DRYRUN}" == true ]]; then
info "SourceGuardian PHP ${PHPv} enabled in dry run mode."
else
if [[ -f "/usr/lib/php/loaders/sourceguardian/ixed.${PHPv}.lin" && -n $(command -v "php${PHPv}") ]]; then
cat > "/etc/php/${PHPv}/mods-available/sourceguardian.ini" <<EOL
@@ -210,7 +210,7 @@ EOL
fi
# Restart PHP-fpm server.
if "${DRYRUN}"; then
if [[ "${DRYRUN}" == true ]]; then
info "php${PHPv}-fpm reloaded in dry run mode."
else
if [[ $(pgrep -c "php-fpm${PHPv}") -gt 0 ]]; then
@@ -238,8 +238,8 @@ EOL
function disable_sourceguardian() {
# PHP version.
local PHPv="${1}"
if [ -z "${PHPv}" ]; then
PHPv=${PHP_VERSION:-"7.4"}
if [[ -z "${PHPv}" ]]; then
PHPv=${DEFAULT_PHP_VERSION:-"7.4"}
fi
echo "Disabling SourceGuardian PHP ${PHPv} loader"
@@ -254,8 +254,8 @@ function disable_sourceguardian() {
function remove_sourceguardian() {
# PHP version.
local PHPv="${1}"
if [ -z "${PHPv}" ]; then
PHPv=${PHP_VERSION:-"7.4"}
if [[ -z "${PHPv}" ]]; then
PHPv=${DEFAULT_PHP_VERSION:-"7.4"}
fi
echo "Uninstalling SourceGuardian PHP ${PHPv} loader..."
@@ -327,7 +327,7 @@ function init_phploader_install() {
# Install PHP loader.
if [[ "${PHPv}" != "unsupported" && ! $(version_older_than "${PHPv}" "5.6") ]]; then
if "${AUTO_INSTALL}"; then
if [[ "${AUTO_INSTALL}" == true ]]; then
# PHP Loader.
if [ -z "${SELECTED_PHP_LOADER}" ]; then
SELECTED_PHP_LOADER=${PHP_LOADER:-""}
@@ -379,13 +379,6 @@ function init_phploader_install() {
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"
for PHPver in 5.6 7.0 7.1 7.2 7.3 7.4 8.0; do
enable_ioncube "${PHPver}"
done
@@ -403,13 +396,6 @@ function init_phploader_install() {
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"
Versions="5.6 7.0 7.1 7.2 7.3 7.4 8.0"
for PHPver in ${Versions}; do
enable_sourceguardian "${PHPver}"
@@ -431,23 +417,7 @@ function init_phploader_install() {
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_ioncube "8.0"
#enable_sourceguardian "5.6"
#enable_sourceguardian "7.0"
#enable_sourceguardian "7.1"
#enable_sourceguardian "7.2"
#enable_sourceguardian "7.3"
#enable_sourceguardian "7.4"
#enable_sourceguardian "8.0"
Versions="5.6 7.0 7.1 7.2 7.3 7.4 8.0"
Versions="5.6 7.0 7.1 7.2 7.3 7.4 8.0 8.1"
for PHPver in ${Versions}; do
enable_ioncube "${PHPver}"
enable_sourceguardian "${PHPver}"