#!/usr/bin/env bash # PHP Installer # Min. Requirement : GNU/Linux Ubuntu 14.04 & 16.04 # Last Build : 05/11/2019 # Author : ESLabs.ID (eslabs.id@gmail.com) # Since Version : 1.0.0 # Include helper functions. if [ "$(type -t run)" != "function" ]; then BASEDIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd ) # shellchechk source=scripts/helper.sh # shellcheck disable=SC1090 . "${BASEDIR}/helper.sh" fi # Make sure only root can run this installer script. requires_root function add_php_repo() { echo "Add Ondrej's PHP repository..." DISTRIB_NAME=${DISTRIB_NAME:-$(get_distrib_name)} DISTRIB_REPO=${DISTRIB_REPO:-$(get_release_name)} case ${DISTRIB_NAME} in debian) if [ ! -f "/etc/apt/sources.list.d/ondrej-php-${DISTRIB_REPO}.list" ]; then run touch "/etc/apt/sources.list.d/ondrej-php-${DISTRIB_REPO}.list" run bash -c "echo 'deb https://packages.sury.org/php/ ${DISTRIB_REPO} main' > /etc/apt/sources.list.d/ondrej-php-${DISTRIB_REPO}.list" run bash -c "wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg" run apt-get -qq update -y else warning "PHP repository already exists." fi ;; ubuntu) # Fix for NO_PUBKEY key servers error run apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 4F4EA0AAE5267A6C run add-apt-repository -y ppa:ondrej/php run apt-get -qq update -y ;; *) fail "Unable to install LEMPer: this GNU/Linux distribution is not dpkg/yum enabled." ;; esac } function install_php_fpm() { # PHP version. local PHPv="${1}" if [ -z "${PHPv}" ]; then PHPv=${PHP_VERSION:-"7.3"} fi local PHP_PKGS=() export PHP_IS_INSTALLED="no" # Checking if php already installed. if [[ -n $(command -v "php${PHPv}") ]]; then PHP_IS_INSTALLED="yes" warning "PHP${PHPv} & FPM package already installed..." else # Add repo first add_php_repo echo "Installing PHP${PHPv} & FPM..." if hash apt-get 2>/dev/null; then PHP_PKGS=("php${PHPv} php${PHPv}-bcmath php${PHPv}-cli php${PHPv}-common \ php${PHPv}-curl php${PHPv}-dev php${PHPv}-fpm php${PHPv}-mysql php${PHPv}-gd \ php${PHPv}-gmp php${PHPv}-imap php${PHPv}-intl php${PHPv}-json \ php${PHPv}-mbstring php${PHPv}-opcache php${PHPv}-pspell php${PHPv}-readline \ php${PHPv}-ldap php${PHPv}-snmp php${PHPv}-soap php${PHPv}-sqlite3 \ php${PHPv}-tidy php${PHPv}-xml php${PHPv}-xmlrpc php${PHPv}-xsl php${PHPv}-zip \ php-pear php-xml pkg-php-tools spawn-fcgi fcgiwrap" "${PHP_PKGS[@]}") if [[ "${#PHP_PKGS[@]}" -gt 0 ]]; then echo "Installing PHP${PHPv} & FPM packages..." # shellcheck disable=SC2068 run apt-get -qq install -y ${PHP_PKGS[@]} fi if [[ -n $(command -v "php${PHPv}") ]]; then status "PHP${PHPv} & FPM packages installed." fi # Install php geoip? if "${AUTO_INSTALL}"; then local INSTALL_PHPGEOIP="y" else while [[ "${INSTALL_PHPGEOIP}" != "y" && "${INSTALL_PHPGEOIP}" != "n" ]]; do read -rp "Do you want to install PHP GeoIP for geolocation? [y/n]: " \ -i n -e INSTALL_PHPGEOIP done fi if [[ ${INSTALL_PHPGEOIP} == Y* || ${INSTALL_PHPGEOIP} == y* ]]; then echo "Installing PHP GeoIP module..." if [ "${PHPv//.}" -lt "70" ]; then #run mkdir -p /usr/lib/php/php-helper run apt-get -qq install -y php-geoip else run pecl install geoip-1.1.1 # Enable Mcrypt module. echo "Updating PHP ini file with GeoIP module..." run bash -c "echo extension=geoip.so > /etc/php/${PHPv}/mods-available/geoip.ini" if [ ! -f "/etc/php/${PHPv}/cli/conf.d/20-geoip.ini" ]; then run ln -s "/etc/php/${PHPv}/mods-available/geoip.ini" \ "/etc/php/${PHPv}/cli/conf.d/20-geoip.ini" fi if [ ! -f "/etc/php/${PHPv}/fpm/conf.d/20-geoip.ini" ]; then run ln -s "/etc/php/${PHPv}/mods-available/geoip.ini" \ "/etc/php/${PHPv}/fpm/conf.d/20-geoip.ini" fi fi fi # Install php mcrypt? if "${AUTO_INSTALL}"; then local INSTALL_PHPMCRYPT="y" else while [[ "${INSTALL_PHPMCRYPT}" != "y" && "${INSTALL_PHPMCRYPT}" != "n" ]]; do read -rp "Do you want to install PHP Mcrypt for encryption/decryption? [y/n]: " \ -i n -e INSTALL_PHPMCRYPT done fi if [[ ${INSTALL_PHPMCRYPT} == Y* || ${INSTALL_PHPMCRYPT} == y* ]]; then echo "Installing PHP Mcrypt module..." if [ "${PHPv//.}" -lt "72" ]; then run apt-get -qq install -y "php${PHPv}-mcrypt" elif [ "${PHPv}" == "7.2" ]; then run apt-get -qq install -y gcc make autoconf libc-dev pkg-config \ libmcrypt-dev libreadline-dev && \ run pecl install mcrypt-1.0.1 # Enable Mcrypt module. echo "Updating PHP ini file with Mcrypt module..." run bash -c "echo extension=mcrypt.so > /etc/php/${PHPv}/mods-available/mcrypt.ini" if [ ! -f "/etc/php/${PHPv}/cli/conf.d/20-mcrypt.ini" ]; then run ln -s "/etc/php/${PHPv}/mods-available/mcrypt.ini" \ "/etc/php/${PHPv}/cli/conf.d/20-mcrypt.ini" fi if [ ! -f "/etc/php/${PHPv}/fpm/conf.d/20-mcrypt.ini" ]; then run ln -s "/etc/php/${PHPv}/mods-available/mcrypt.ini" \ "/etc/php/${PHPv}/fpm/conf.d/20-mcrypt.ini" fi else run apt-get -qq install -y dh-php # Use libsodium instead. echo "Mcrypt module is deprecated for PHP ${PHPv} or greater, you should using Libsodium or OpenSSL for encryption." fi fi elif hash yum 2>/dev/null; then if [ "${VERSION_ID}" == "5" ]; then yum -y update #yum -y localinstall "${NGX_PACKAGE}" --nogpgcheck else yum -y update #yum -y localinstall "${NGX_PACKAGE}" fi else fail "Unable to install NGiNX, this GNU/Linux distribution is not dpkg/yum enabled." fi # Create PHP log dir. if [ ! -d /var/log/php ]; then mkdir -p /var/log/php fi fi } # 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}" ARCH=${ARCH:-$(uname -p)} if [[ "${ARCH}" == "x86_64" ]]; then run wget -q "http://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 "http://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 echo "Installing latest ionCube PHP loader..." run mv -f ioncube /usr/lib/php/loaders/ run cd "${CURRENT_DIR}" } # Enable ionCube Loader function enable_ioncube() { # PHP version. local PHPv="${1}" if [ -z "${PHPv}" ]; then PHPv=${PHP_VERSION:-"7.3"} fi echo "Enabling ionCube PHP${PHPv} loader" if "${DRYRUN}"; then warning "ionCube PHP${PHPv} enabled in dryrun mode." else if [ -f "/usr/lib/php/loaders/ioncube/ioncube_loader_lin_${PHPv}.so" ]; then cat > "/etc/php/${PHPv}/mods-available/ioncube.ini" < "/etc/php/${PHPv}/mods-available/sourceguardian.ini" <> "/etc/php/${PHPv}/fpm/php.ini" <> "/etc/php/${PHPv}/fpm/pool.d/www.conf" <> "/etc/php/${PHPv}/fpm/pool.d/${POOLNAME}.conf" <