# Copyright (C) 2014 - 2017, Teddysun # # This file is part of the LAMP script. # # LAMP is a powerful bash script for the installation of # Apache + PHP + MySQL/MariaDB/Percona and so on. # You can install Apache + PHP + MySQL/MariaDB/Percona 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 apache apache_preinstall_settings(){ display_menu apache 2 display_menu_multi apache_modules last if [[ "$apache" != "do_not_install" ]];then if [ "$apache" == "${apache2_2_filename}" ];then apache_configure_args="--prefix=${apache_location} \ --with-included-apr \ --with-mpm=prefork \ --with-ssl \ --enable-so \ --enable-suexec \ --enable-deflate=shared \ --enable-expires=shared \ --enable-ssl=shared \ --enable-headers=shared \ --enable-rewrite=shared \ --enable-static-support \ --enable-modules=all \ --enable-mods-shared=all" elif [ "$apache" == "${apache2_4_filename}" ];then apache_configure_args="--prefix=${apache_location} \ --with-pcre=${depends_prefix}/pcre \ --with-mpm=event \ --with-included-apr \ --with-ssl \ --with-nghttp2 \ --enable-modules=reallyall \ --enable-mods-shared=reallyall" fi fi } #Install apache install_apache(){ log "Info" "Starting to install dependencies packages for Apache..." local apt_list=(openssl libssl-dev libxml2-dev lynx lua-expat-dev) local yum_list=(zlib-devel openssl-devel libxml2-devel lynx expat-devel) if check_sys packageManager apt; then for depend in ${apt_list[@]}; do error_detect_depends "apt-get -y install ${depend}" done elif check_sys packageManager yum; then for depend in ${yum_list[@]}; do error_detect_depends "yum -y install ${depend}" done fi log "Info" "Install dependencies packages for Apache completed..." if ! grep -qE "^/usr/local/lib" /etc/ld.so.conf.d/*.conf; then echo "/usr/local/lib" > /etc/ld.so.conf.d/locallib.conf fi if [ "$apache" == "${apache2_2_filename}" ]; then cd ${cur_dir}/software/ download_file "${apache2_2_filename}.tar.gz" tar zxf ${apache2_2_filename}.tar.gz cd ${apache2_2_filename} if ubuntuversion 12.04; then sed -i '/SSL_PROTOCOL_SSLV2/d' modules/ssl/ssl_engine_io.c fi LDFLAGS=-ldl error_detect "./configure ${apache_configure_args}" error_detect "parallel_make" error_detect "make install" unset LDFLAGS config_apache 2.2 elif [ "$apache" == "${apache2_4_filename}" ]; then check_installed "install_pcre" "${depends_prefix}/pcre" check_installed "install_openssl" "${openssl_location}" install_nghttp2 cd ${cur_dir}/software/ download_file "${apr_filename}.tar.gz" tar zxf ${apr_filename}.tar.gz download_file "${apr_util_filename}.tar.gz" tar zxf ${apr_util_filename}.tar.gz download_file "${apache2_4_filename}.tar.gz" tar zxf ${apache2_4_filename}.tar.gz cd ${apache2_4_filename} mv ${cur_dir}/software/${apr_filename} srclib/apr mv ${cur_dir}/software/${apr_util_filename} srclib/apr-util LDFLAGS=-ldl if [ -d ${openssl_location} ]; then apache_configure_args=`echo ${apache_configure_args} | sed -e "s@--with-ssl@--with-ssl=${openssl_location}@"` fi error_detect "./configure ${apache_configure_args}" error_detect "parallel_make" error_detect "make install" unset LDFLAGS config_apache 2.4 fi } config_apache(){ id -u apache >/dev/null 2>&1 [ $? -ne 0 ] && groupadd apache && useradd -M -s /sbin/nologin -g apache apache [ ! -d ${web_root_dir} ] && mkdir -p ${web_root_dir} && chmod -R 755 ${web_root_dir} local version=$1 if [ -f ${apache_location}/conf/httpd.conf ]; then cp -f ${apache_location}/conf/httpd.conf ${apache_location}/conf/httpd.conf.bak fi grep -E -q "^\s*#\s*Include conf/extra/httpd-vhosts.conf" ${apache_location}/conf/httpd.conf && \ sed -i 's#^\s*\#\s*Include conf/extra/httpd-vhosts.conf#Include conf/extra/httpd-vhosts.conf#' ${apache_location}/conf/httpd.conf || \ sed -i '$aInclude conf/extra/httpd-vhosts.conf' ${apache_location}/conf/httpd.conf mv ${apache_location}/conf/extra/httpd-vhosts.conf ${apache_location}/conf/extra/httpd-vhosts.conf.bak mkdir -p ${apache_location}/conf/vhost/ touch ${apache_location}/conf/vhost/none.conf cat > /etc/logrotate.d/httpd < ${apache_location}/conf/extra/httpd-vhosts.conf < ServerName localhost ServerAlias localhost DocumentRoot ${web_root_dir} SetOutputFilter DEFLATE Options FollowSymLinks AllowOverride All Order Deny,Allow Allow from All DirectoryIndex index.php index.html index.htm Include ${apache_location}/conf/vhost/*.conf EOF sed -i 's/^User.*/User apache/i' ${apache_location}/conf/httpd.conf sed -i 's/^Group.*/Group apache/i' ${apache_location}/conf/httpd.conf sed -i 's/^#ServerName www.example.com:80/ServerName 0.0.0.0:80/' ${apache_location}/conf/httpd.conf sed -i 's/^ServerAdmin you@example.com/ServerAdmin admin@localhost/' ${apache_location}/conf/httpd.conf sed -i 's@^#Include conf/extra/httpd-info.conf@Include conf/extra/httpd-info.conf@' ${apache_location}/conf/httpd.conf sed -i 's@DirectoryIndex index.html@DirectoryIndex index.html index.php@' ${apache_location}/conf/httpd.conf sed -i "s@^DocumentRoot.*@DocumentRoot \"${web_root_dir}\"@" ${apache_location}/conf/httpd.conf sed -i "s@^@@" ${apache_location}/conf/httpd.conf echo "ServerTokens ProductOnly" >> ${apache_location}/conf/httpd.conf if [ ${version} == "2.4" ]; then sed -i -r 's/^#(.*mod_cache.so)/\1/' ${apache_location}/conf/httpd.conf sed -i -r 's/^#(.*mod_cache_socache.so)/\1/' ${apache_location}/conf/httpd.conf sed -i -r 's/^#(.*mod_socache_shmcb.so)/\1/' ${apache_location}/conf/httpd.conf sed -i -r 's/^#(.*mod_socache_dbm.so)/\1/' ${apache_location}/conf/httpd.conf sed -i -r 's/^#(.*mod_socache_memcache.so)/\1/' ${apache_location}/conf/httpd.conf sed -i -r 's/^#(.*mod_proxy.so)/\1/' ${apache_location}/conf/httpd.conf sed -i -r 's/^#(.*mod_proxy_connect.so)/\1/' ${apache_location}/conf/httpd.conf sed -i -r 's/^#(.*mod_proxy_ftp.so)/\1/' ${apache_location}/conf/httpd.conf sed -i -r 's/^#(.*mod_proxy_http.so)/\1/' ${apache_location}/conf/httpd.conf sed -i -r 's/^#(.*mod_suexec.so)/\1/' ${apache_location}/conf/httpd.conf sed -i -r 's/^#(.*mod_vhost_alias.so)/\1/' ${apache_location}/conf/httpd.conf sed -i -r 's/^#(.*mod_rewrite.so)/\1/' ${apache_location}/conf/httpd.conf sed -i -r 's/^#(.*mod_deflate.so)/\1/' ${apache_location}/conf/httpd.conf sed -i -r 's/^#(.*mod_expires.so)/\1/' ${apache_location}/conf/httpd.conf sed -i -r 's/^#(.*mod_ssl.so)/\1/' ${apache_location}/conf/httpd.conf sed -i -r 's/^#(.*mod_http2.so)/\1/' ${apache_location}/conf/httpd.conf echo "ProtocolsHonorOrder On" >> ${apache_location}/conf/httpd.conf echo "Protocols h2 http/1.1" >> ${apache_location}/conf/httpd.conf [ -d ${openssl_location} ] && sed -i "s@^export LD_LIBRARY_PATH.*@export LD_LIBRARY_PATH=\$LD_LIBRARY_PATH:${openssl_location}/lib@" ${apache_location}/bin/envvars sed -i 's/Allow from All/Require all granted/' ${apache_location}/conf/extra/httpd-vhosts.conf sed -i 's/Require host .example.com/Require host localhost/g' ${apache_location}/conf/extra/httpd-info.conf cp -f ${cur_dir}/conf/httpd24-ssl.conf ${apache_location}/conf/extra/httpd-ssl.conf elif [ ${version} == "2.2" ]; then sed -i -r 's/^(.*mod_unique_id.so)/\#&/' ${apache_location}/conf/httpd.conf sed -i 's/Allow from .example.com/Allow from localhost/g' ${apache_location}/conf/extra/httpd-info.conf cp -f ${cur_dir}/conf/httpd22-ssl.conf ${apache_location}/conf/extra/httpd-ssl.conf fi rm -f /etc/init.d/httpd if centosversion 6; then cp -f ${cur_dir}/conf/httpd-init-centos6 /etc/init.d/httpd else cp -f ${cur_dir}/conf/httpd-init /etc/init.d/httpd fi sed -i "s#^apache_location=.*#apache_location=$apache_location#" /etc/init.d/httpd chmod +x /etc/init.d/httpd rm -fr /var/log/httpd /usr/sbin/httpd ln -s ${apache_location}/bin/httpd /usr/sbin/httpd ln -s ${apache_location}/logs /var/log/httpd cp -f ${cur_dir}/conf/index.html ${web_root_dir} cp -f ${cur_dir}/conf/index_cn.html ${web_root_dir} cp -f ${cur_dir}/conf/lamp.gif ${web_root_dir} cp -f ${cur_dir}/conf/jquery.js ${web_root_dir} cp -f ${cur_dir}/conf/p.php ${web_root_dir} cp -f ${cur_dir}/conf/p_cn.php ${web_root_dir} cp -f ${cur_dir}/conf/phpinfo.php ${web_root_dir} cp -f ${cur_dir}/conf/favicon.ico ${web_root_dir} chown -R apache.apache ${web_root_dir} boot_start httpd } install_apache_modules(){ if_in_array "${mod_wsgi_filename}" "${apache_modules_install}" && install_mod_wsgi if_in_array "${mod_jk_filename}" "${apache_modules_install}" && install_mod_jk } install_mod_wsgi(){ cd ${cur_dir}/software/ log "Info" "${mod_wsgi_filename} install start..." download_file "${mod_wsgi_filename}.tar.gz" tar zxf ${mod_wsgi_filename}.tar.gz cd ${mod_wsgi_filename} error_detect "./configure --with-apxs=${apache_location}/bin/apxs" error_detect "make" error_detect "make install" # add mod_wsgi to httpd.conf if [[ `grep -E -c "^\s*LoadModule wsgi_module modules/mod_wsgi.so" ${apache_location}/conf/httpd.conf` -eq 0 ]]; then lnum=$(sed -n '/LoadModule/=' ${apache_location}/conf/httpd.conf | tail -1) sed -i "${lnum}aLoadModule wsgi_module modules/mod_wsgi.so" ${apache_location}/conf/httpd.conf fi log "Info" "${mod_wsgi_filename} install completed..." } install_mod_jk(){ cd ${cur_dir}/software/ log "Info" "${mod_jk_filename} install start..." download_file "${mod_jk_filename}.tar.gz" tar zxf ${mod_jk_filename}.tar.gz cd ${mod_jk_filename}/native error_detect "./configure --with-apxs=${apache_location}/bin/apxs --enable-api-compatibility" error_detect "make" error_detect "make install" # add mod_jk to httpd.conf if [[ `grep -E -c "^\s*LoadModule jk_module modules/mod_jk.so" ${apache_location}/conf/httpd.conf` -eq 0 ]]; then lnum=$(sed -n '/LoadModule/=' ${apache_location}/conf/httpd.conf | tail -1) sed -i "${lnum}aLoadModule jk_module modules/mod_jk.so" ${apache_location}/conf/httpd.conf fi log "Info" "${mod_jk_filename} install completed..." }