# Copyright (C) 2013 - 2022 Teddysun # # This file is part of the LAMP script. # # LAMP is a powerful bash script for the installation of # Apache + PHP + MySQL/MariaDB and so on. # You can install Apache + PHP + MySQL/MariaDB in an very easy way. # Just need to input numbers to choose what you want to install before installation. # And all things will be done in a few minutes. # # Website: https://lamp.sh # Github: https://github.com/teddysun/lamp #Pre-installation php modules php_modules_preinstall_settings(){ if [ "${php}" == "do_not_install" ]; then php_modules_install="do_not_install" else phpConfig=${php_location}/bin/php-config echo echo "${php} available modules:" # Delete some modules & change some module version if [ "${php}" == "${php5_6_filename}" ]; then php_modules_arr=(${php_modules_arr[@]#${php_libsodium_filename}}) php_modules_arr=(${php_modules_arr[@]#${swoole_filename}}) php_modules_arr=(${php_modules_arr[@]#${yaf_filename}}) php_modules_arr=(${php_modules_arr[@]#${yar_filename}}) php_modules_arr=(${php_modules_arr[@]#${pdflib_filename}}) php_modules_arr=(${php_modules_arr[@]#${phalcon_filename}}) else php_modules_arr=(${php_modules_arr[@]#${xcache_filename}}) php_modules_arr=(${php_modules_arr[@]/#${xdebug_filename}/${xdebug_filename2}}) php_modules_arr=(${php_modules_arr[@]/#${php_redis_filename}/${php_redis_filename2}}) php_modules_arr=(${php_modules_arr[@]/#${php_memcached_filename}/${php_memcached_filename2}}) php_modules_arr=(${php_modules_arr[@]/#${php_graphicsmagick_filename}/${php_graphicsmagick_filename2}}) fi # Swoole supports only PHP 7.2+ if [[ "${php}" =~ ^php-7.[0-1].+$ ]]; then php_modules_arr=(${php_modules_arr[@]#${swoole_filename}}) fi # PDFlib supports only PHP 7.3+ # Phalcon supports only PHP 7.3+ # Reference URL: https://github.com/phalcon/cphalcon/releases/tag/v4.1.2 if [[ "${php}" =~ ^php-7.[0-2].+$ ]]; then php_modules_arr=(${php_modules_arr[@]#${phalcon_filename}}) php_modules_arr=(${php_modules_arr[@]#${pdflib_filename}}) fi # Delete some modules (PHP 8.0 not support now) & change some module version if [[ "${php}" =~ ^php-8.0.+$ ]]; then php_modules_arr=(${php_modules_arr[@]#${phalcon_filename}}) php_modules_arr=(${php_modules_arr[@]/#${xdebug_filename2}/${xdebug_filename3}}) php_modules_arr=(${php_modules_arr[@]#${ionCube_filename}}) php_modules_arr=(${php_modules_arr[@]#${php_imagemagick_filename}}) php_modules_arr=(${php_modules_arr[@]#${php_memcached_filename2}}) fi display_menu_multi php_modules last fi } #Pre-installation phpmyadmin phpmyadmin_preinstall_settings(){ if [ "${php}" == "do_not_install" ]; then phpmyadmin="do_not_install" else # phpMyAdmin 5.x removed support of old PHP versions (5.6, 7.0) # Reference URL: https://www.phpmyadmin.net/news/2019/12/26/phpmyadmin-500-released/ if [[ "${php}" =~ ^php-7.[1-4].+$ ]] || [[ "${php}" =~ ^php-8.0.+$ ]]; then phpmyadmin_arr=(${phpmyadmin_arr[@]/#${phpmyadmin_filename}/${phpmyadmin_filename2}}) fi display_menu_multi phpmyadmin 1 fi } #Pre-installation kodexplorer kodexplorer_preinstall_settings(){ if [ "${php}" == "do_not_install" ] || [[ "${php}" =~ ^php-8.0.+$ ]]; then kodexplorer="do_not_install" else display_menu kodexplorer 1 fi } install_php_modules(){ local phpConfig=${1} if_in_array "${ionCube_filename}" "${php_modules_install}" && install_ionCube "${phpConfig}" if_in_array "${pdflib_filename}" "${php_modules_install}" && install_pdflib "${phpConfig}" if_in_array "${apcu_filename}" "${php_modules_install}" && install_apcu "${phpConfig}" if_in_array "${php_imagemagick_filename}" "${php_modules_install}" && install_php_imagesmagick "${phpConfig}" if_in_array "${php_mongo_filename}" "${php_modules_install}" && install_php_mongo "${phpConfig}" if_in_array "${xcache_filename}" "${php_modules_install}" && install_xcache "${phpConfig}" if_in_array "${php_libsodium_filename}" "${php_modules_install}" && install_php_libsodium "${phpConfig}" if_in_array "${swoole_filename}" "${php_modules_install}" && install_swoole "${phpConfig}" if_in_array "${yaf_filename}" "${php_modules_install}" && install_yaf "${phpConfig}" if_in_array "${yar_filename}" "${php_modules_install}" && install_yar "${phpConfig}" if_in_array "${grpc_filename}" "${php_modules_install}" && install_grpc "${phpConfig}" if_in_array "${phalcon_filename}" "${php_modules_install}" && install_phalcon "${phpConfig}" if if_in_array "${php_graphicsmagick_filename}" "${php_modules_install}" || \ if_in_array "${php_graphicsmagick_filename2}" "${php_modules_install}"; then install_php_graphicsmagick "${phpConfig}" fi if if_in_array "${php_redis_filename}" "${php_modules_install}" || \ if_in_array "${php_redis_filename2}" "${php_modules_install}"; then install_php_redis "${phpConfig}" fi if if_in_array "${php_memcached_filename}" "${php_modules_install}" || \ if_in_array "${php_memcached_filename2}" "${php_modules_install}"; then install_php_memcached "${phpConfig}" fi if if_in_array "${xdebug_filename}" "${php_modules_install}" || \ if_in_array "${xdebug_filename2}" "${php_modules_install}" || \ if_in_array "${xdebug_filename3}" "${php_modules_install}"; then install_xdebug "${phpConfig}" fi } install_phpmyadmin_modules(){ if if_in_array "${phpmyadmin_filename}" "${phpmyadmin_install}" || \ if_in_array "${phpmyadmin_filename2}" "${phpmyadmin_install}"; then install_phpmyadmin fi if_in_array "${adminer_filename}" "${phpmyadmin_install}" && install_adminer } install_php_depends(){ _info "Installing dependencies for PHP..." if check_sys packageManager apt; then apt_depends=( cmake autoconf patch m4 bison pkg-config autoconf2.13 libbz2-dev libgmp-dev libicu-dev libldb-dev libldap-2.4-2 libldap2-dev libsasl2-dev libsasl2-modules-ldap libc-client2007e-dev libkrb5-dev libpam0g-dev libonig-dev libxslt1-dev zlib1g-dev libpcre3-dev libtool libtidy-dev libsqlite3-dev libjpeg-dev libpng-dev libfreetype6-dev libpspell-dev libmhash-dev libenchant-dev libmcrypt-dev libcurl4-gnutls-dev libwebp-dev libxpm-dev libvpx-dev libreadline-dev snmp libsnmp-dev libzip-dev ) for depend in ${apt_depends[@]}; do error_detect_depends "apt-get -y install ${depend}" done if is_64bit; then if [ ! -d /usr/lib64 ] && [ -d /usr/lib ]; then ln -sf /usr/lib /usr/lib64 fi if [ -f /usr/include/gmp-x86_64.h ]; then ln -sf /usr/include/gmp-x86_64.h /usr/include/ elif [ -f /usr/include/x86_64-linux-gnu/gmp.h ]; then ln -sf /usr/include/x86_64-linux-gnu/gmp.h /usr/include/ fi ln -sf /usr/lib/x86_64-linux-gnu/libldap* /usr/lib64/ ln -sf /usr/lib/x86_64-linux-gnu/liblber* /usr/lib64/ if [ -d /usr/include/x86_64-linux-gnu/curl ] && [ ! -d /usr/include/curl ]; then ln -sf /usr/include/x86_64-linux-gnu/curl /usr/include/ fi create_lib_link libc-client.a create_lib_link libc-client.so else if [ -f /usr/include/gmp-i386.h ]; then ln -sf /usr/include/gmp-i386.h /usr/include/ elif [ -f /usr/include/i386-linux-gnu/gmp.h ]; then ln -sf /usr/include/i386-linux-gnu/gmp.h /usr/include/ fi ln -sf /usr/lib/i386-linux-gnu/libldap* /usr/lib/ ln -sf /usr/lib/i386-linux-gnu/liblber* /usr/lib/ if [ -d /usr/include/i386-linux-gnu/curl ] && [ ! -d /usr/include/curl ]; then ln -sf /usr/include/i386-linux-gnu/curl /usr/include/ fi fi # Fixed older PHP installation in Debian 10 or Ubuntu 20 if debianversion 10 || ubuntuversion 20; then install_older_php_pre fi elif check_sys packageManager yum; then yum_depends=( cmake autoconf patch m4 bison bzip2-devel pam-devel gmp-devel libicu-devel curl-devel pcre-devel libtool-libs libtool-ltdl-devel libwebp-devel libXpm-devel libvpx-devel libjpeg-devel libpng-devel freetype-devel oniguruma-devel aspell-devel enchant-devel readline-devel libtidy-devel sqlite-devel openldap-devel libxslt-devel net-snmp net-snmp-devel krb5-devel ) for depend in ${yum_depends[@]}; do error_detect_depends "yum -y install ${depend}" done if yum list 2>/dev/null | grep -q "libc-client-devel"; then error_detect_depends "yum -y install libc-client-devel" elif yum list 2>/dev/null | grep -q "uw-imap-devel"; then error_detect_depends "yum -y install uw-imap-devel" else _error "There is no rpm package libc-client-devel or uw-imap-devel, please check it and try again." fi install_mhash install_libmcrypt install_mcrypt install_libzip # Fixed error: Autoconf version 2.68 or higher is required in CentOS 6 if centosversion 6; then # Uninstall old autoconf if rpm -qa | grep -q autoconf; then rpm -e --nodeps autoconf-2.63 fi install_autoconf # Fixed PHP 7.4+ installation in CentOS 6 if [[ "${php}" == "${php7_4_filename}" ]] || [[ "${php}" == "${php8_0_filename}" ]]; then install_php74_centos6 fi fi fi install_libiconv install_re2c # Support Argon2 Password Hash (Only PHP 7.2+) # Reference URL: https://wiki.php.net/rfc/argon2_password_hash if [[ "${php}" =~ ^php-7.[2-4].+$ ]] || [[ "${php}" =~ ^php-8.0.+$ ]]; then install_argon2 fi _info "Install dependencies for PHP completed..." } install_older_php_pre(){ # Fixed configure: error: freetype-config not found if [ ! -f "/usr/local/bin/freetype-config" ] && [ ! -f "/usr/bin/freetype-config" ]; then { echo '#!/bin/sh'; echo 'exec pkg-config "$@" freetype2'; } > /usr/local/bin/freetype-config chmod +x /usr/local/bin/freetype-config fi # Fixed configure: error: Unable to detect ICU prefix or /usr/bin/icu-config failed. Please verify ICU install prefix and make sure icu-config works. if is_64bit; then debianversion 10 && cp -f ${cur_dir}/conf/icu-config_debian10_amd64 /usr/bin/icu-config ubuntuversion 20 && cp -f ${cur_dir}/conf/icu-config_ubuntu20_amd64 /usr/bin/icu-config else debianversion 10 && cp -f ${cur_dir}/conf/icu-config_debian10_i386 /usr/bin/icu-config ubuntuversion 20 && cp -f ${cur_dir}/conf/icu-config_ubuntu20_i386 /usr/bin/icu-config fi chmod +x /usr/bin/icu-config } install_php74_centos6(){ local libdir="" is_64bit && libdir="lib64" || libdir="lib" # Fixed configure: error: Package requirements (sqlite3 > 3.7.4) were not met install_sqlite3 cp -pf /usr/local/lib/pkgconfig/sqlite3.pc /usr/${libdir}/pkgconfig # Fixed configure: error: Package requirements (icu-uc >= 50.1 icu-io icu-i18n) were not met install_icu4c cp -pf /usr/local/lib/pkgconfig/icu*.pc /usr/${libdir}/pkgconfig # Fixed configure: error: Package requirements (krb5-gssapi krb5) were not met cat > /usr/${libdir}/pkgconfig/krb5-gssapi.pc < /usr/${libdir}/pkgconfig/krb5.pc < /usr/${libdir}/pkgconfig/libjpeg.pc < /usr/${libdir}/pkgconfig/libsasl2.pc < /usr/${libdir}/pkgconfig/oniguruma.pc < /etc/ld.so.conf.d/libiconvlib.conf fi _info "Install ${libiconv_filename} completed..." fi } install_re2c(){ if [ ! -e "/usr/local/bin/re2c" ]; then cd ${cur_dir}/software/ _info "Installing ${re2c_filename}..." download_file "${re2c_filename}.tar.gz" "${re2c_filename_url}" tar zxf ${re2c_filename}.tar.gz cd ${re2c_filename} error_detect "./configure" error_detect "make" error_detect "make install" _info "Install ${re2c_filename} completed..." fi } install_mhash(){ if [ ! -e "/usr/local/lib/libmhash.a" ]; then cd ${cur_dir}/software/ _info "Installing ${mhash_filename}..." download_file "${mhash_filename}.tar.gz" "${mhash_filename_url}" tar zxf ${mhash_filename}.tar.gz cd ${mhash_filename} error_detect "./configure" error_detect "parallel_make" error_detect "make install" _info "Install ${mhash_filename} completed..." fi } install_mcrypt(){ if [ ! -e "/usr/local/bin/mcrypt" ]; then cd ${cur_dir}/software/ _info "Installing ${mcrypt_filename}..." download_file "${mcrypt_filename}.tar.gz" "${mcrypt_filename_url}" tar zxf ${mcrypt_filename}.tar.gz cd ${mcrypt_filename} ldconfig error_detect "./configure" error_detect "parallel_make" error_detect "make install" _info "Install ${mcrypt_filename} completed..." fi } install_libmcrypt(){ if [ ! -e "/usr/local/lib/libmcrypt.la" ]; then cd ${cur_dir}/software/ _info "Installing ${libmcrypt_filename}..." download_file "${libmcrypt_filename}.tar.gz" "${libmcrypt_filename_url}" tar zxf ${libmcrypt_filename}.tar.gz cd ${libmcrypt_filename} error_detect "./configure" error_detect "parallel_make" error_detect "make install" _info "Install ${libmcrypt_filename} completed..." fi } install_libzip(){ local cmake_bin="$(command -v cmake)" local cmake_ver="$(${cmake_bin} --version | head -1 | grep -oE "[0-9.]+")" if version_lt ${cmake_ver} 3.0.2; then cd ${cur_dir}/software/ _info "Installing ${cmake_filename}..." if is_64bit; then if [ ! -d "${depends_prefix}/cmake" ]; then download_file "${cmake_filename2}.tar.gz" "${cmake_filename_url2}" tar zxf ${cmake_filename2}.tar.gz -C ${depends_prefix} mv ${depends_prefix}/${cmake_filename2} ${depends_prefix}/cmake fi [ -x "${depends_prefix}/cmake/bin/cmake" ] && cmake_bin="${depends_prefix}/cmake/bin/cmake" else download_file "${cmake_filename}.tar.gz" "${cmake_filename_url}" tar zxf ${cmake_filename}.tar.gz cd ${cmake_filename} error_detect "./bootstrap --prefix=${depends_prefix}" error_detect "parallel_make" error_detect "make install" cmake_bin="${depends_prefix}/bin/cmake" fi _info "Install ${cmake_filename} completed..." fi if [ ! -e "/usr/local/bin/zipcmp" ]; then cd ${cur_dir}/software/ _info "Installing ${libzip_filename}..." download_file "${libzip_filename}.tar.gz" "${libzip_filename_url}" tar zxf ${libzip_filename}.tar.gz cd ${libzip_filename} && mkdir build && cd build error_detect "${cmake_bin} .." error_detect "parallel_make" error_detect "make install" is_64bit && cp -pv libzip.pc /usr/lib64/pkgconfig || cp -pv libzip.pc /usr/lib/pkgconfig _info "Install ${libzip_filename} completed..." fi } install_phpmyadmin(){ local pma_file="" local pma_file_url="" if [ -d "${web_root_dir}/phpmyadmin" ]; then rm -rf ${web_root_dir}/phpmyadmin fi if [[ "${php}" =~ ^php-7.[1-4].+$ ]] || [[ "${php}" =~ ^php-8.0.+$ ]]; then pma_file=${phpmyadmin_filename2} pma_file_url=${phpmyadmin_filename2_url} else pma_file=${phpmyadmin_filename} pma_file_url=${phpmyadmin_filename_url} fi cd ${cur_dir}/software _info "Installing ${pma_file}..." download_file "${pma_file}.tar.gz" "${pma_file_url}" tar zxf ${pma_file}.tar.gz mv ${pma_file} ${web_root_dir}/phpmyadmin cp -f ${cur_dir}/conf/config.inc.php ${web_root_dir}/phpmyadmin/config.inc.php mkdir -p ${web_root_dir}/phpmyadmin/{upload,save} chown -R apache:apache ${web_root_dir}/phpmyadmin _info "Install ${pma_file} completed..." } install_adminer(){ _info "Installing ${adminer_filename}..." cd ${cur_dir}/software download_file "${adminer_filename}.php" "${adminer_filename_url}" mv ${adminer_filename}.php ${web_root_dir}/adminer.php chown apache:apache ${web_root_dir}/adminer.php _info "Install ${adminer_filename} completed..." } install_kodexplorer(){ if [ -d "${web_root_dir}/kod" ]; then rm -rf ${web_root_dir}/kod fi cd ${cur_dir}/software _info "Installing ${kodexplorer_filename}..." download_file "${kodexplorer_filename}.tar.gz" "${kodexplorer_filename_url}" tar zxf ${kodexplorer_filename}.tar.gz mv ${kodexplorer_filename} ${web_root_dir}/kod chown -R apache:apache ${web_root_dir}/kod _info "Install ${kodexplorer_filename} completed..." } install_ionCube(){ local phpConfig=${1} local php_version=$(get_php_version "${phpConfig}") local php_extension_dir=$(get_php_extension_dir "${phpConfig}") cd ${cur_dir}/software/ _info "Installing PHP extension ionCube Loader..." if is_64bit; then download_file "${ionCube64_filename}.tar.gz" "${ionCube64_filename_url}" tar zxf ${ionCube64_filename}.tar.gz cp -pf ioncube/ioncube_loader_lin_${php_version}_ts.so ${php_extension_dir}/ else download_file "${ionCube32_filename}.tar.gz" "${ionCube32_filename_url}" tar zxf ${ionCube32_filename}.tar.gz cp -pf ioncube/ioncube_loader_lin_${php_version}_ts.so ${php_extension_dir}/ fi if [ ! -f "${php_location}/php.d/ioncube.ini" ]; then cat > ${php_location}/php.d/ioncube.ini< ${php_location}/php.d/pdflib.ini< ${php_location}/php.d/xcache.ini< ${php_location}/php.d/sodium.ini< ${php_location}/php.d/imagick.ini< ${php_location}/php.d/gmagick.ini</dev/null 2>&1 [ $? -ne 0 ] && groupadd memcached && useradd -M -s /sbin/nologin -g memcached memcached download_file "${memcached_filename}.tar.gz" "${memcached_filename_url}" tar zxf ${memcached_filename}.tar.gz cd ${memcached_filename} error_detect "./configure --prefix=${depends_prefix}/memcached" sed -i "s/\-Werror//" Makefile error_detect "make" error_detect "make install" [ -f "/usr/bin/memcached" ] && rm -f /usr/bin/memcached ln -s ${depends_prefix}/memcached/bin/memcached /usr/bin/memcached if check_sys packageManager apt; then cp -f ${cur_dir}/init.d/memcached-init-debian /etc/init.d/memcached elif check_sys packageManager yum; then cp -f ${cur_dir}/init.d/memcached-init-centos /etc/init.d/memcached fi chmod +x /etc/init.d/memcached boot_start memcached _info "Install ${memcached_filename} completed..." cd ${cur_dir}/software _info "Installing ${libmemcached_filename}..." if check_sys packageManager apt; then apt-get -y install libsasl2-dev elif check_sys packageManager yum; then yum -y install cyrus-sasl-plain cyrus-sasl cyrus-sasl-devel cyrus-sasl-lib fi download_file "${libmemcached_filename}.tar.gz" "${libmemcached_filename_url}" tar zxf ${libmemcached_filename}.tar.gz patch -d ${libmemcached_filename} -p0 < ${cur_dir}/src/libmemcached-build.patch cd ${libmemcached_filename} error_detect "./configure --with-memcached=${depends_prefix}/memcached --enable-sasl" error_detect "make" error_detect "make install" _info "Install ${libmemcached_filename} completed..." cd ${cur_dir}/software _info "Installing PHP extension memcached..." if [ "$php" == "${php5_6_filename}" ]; then download_file "${php_memcached_filename}.tgz" "${php_memcached_filename_url}" tar zxf ${php_memcached_filename}.tgz cd ${php_memcached_filename} else download_file "${php_memcached_filename2}.tgz" "${php_memcached_filename2_url}" tar zxf ${php_memcached_filename2}.tgz cd ${php_memcached_filename2} fi error_detect "${php_location}/bin/phpize" error_detect "./configure --with-php-config=${phpConfig}" error_detect "make" error_detect "make install" if [ ! -f "${php_location}/php.d/memcached.ini" ]; then cat > ${php_location}/php.d/memcached.ini<@maxmemory \nmaxmemory $(expr ${Mem} / 8)000000@" ${redis_install_dir}/etc/redis.conf if check_sys packageManager apt; then cp -f ${cur_dir}/init.d/redis-server-init-debian /etc/init.d/redis-server elif check_sys packageManager yum; then cp -f ${cur_dir}/init.d/redis-server-init-centos /etc/init.d/redis-server fi id -u redis >/dev/null 2>&1 [ $? -ne 0 ] && groupadd redis && useradd -M -s /sbin/nologin -g redis redis chown -R redis:redis ${redis_install_dir} chmod +x /etc/init.d/redis-server boot_start redis-server _info "Install ${redis_filename} completed!" else RT=1 _error "Install ${redis_filename} failed." fi if [ ${RT} -eq 0 ]; then cd ${cur_dir}/software/ _info "Installing PHP extension redis..." if [ "$php" == "${php5_6_filename}" ]; then download_file "${php_redis_filename}.tgz" "${php_redis_filename_url}" tar zxf ${php_redis_filename}.tgz cd ${php_redis_filename} else download_file "${php_redis_filename2}.tgz" "${php_redis_filename2_url}" tar zxf ${php_redis_filename2}.tgz cd ${php_redis_filename2} fi error_detect "${php_location}/bin/phpize" error_detect "./configure --enable-redis --with-php-config=${phpConfig}" error_detect "make" error_detect "make install" if [ ! -f "${php_location}/php.d/redis.ini" ]; then cat > ${php_location}/php.d/redis.ini< ${php_location}/php.d/mongodb.ini< ${php_location}/php.d/swoole.ini< ${php_location}/php.d/xdebug.ini< ${php_location}/php.d/yaf.ini< ${php_location}/php.d/msgpack.ini< ${php_location}/php.d/yar.ini< ${php_location}/php.d/psr.ini< ${php_location}/php.d/phalcon.ini< ${php_location}/php.d/apcu.ini< ${php_location}/php.d/grpc.ini<