分析安裝包lnmp中的apache.sh指令碼

來源:互聯網
上載者:User

分析shell指令碼,學習方法,這個其實是在lnmp環境下再安裝apache,實現lnmpa環境。

#!/bin/bash#定義PATH變數PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin#聲明PATH為環境變數export PATH# Check if user is root#id -u 目前使用者的uid,也可以使用反引號`id -u`,效果一樣,0為root的使用者idif [ $(id -u) != "0" ]; then    echo "Error: You must be root to run this script, please use root to install lnmp"    exit 1fi#清屏操作clear#可以識別特殊字元printf "=======================================================================\n"printf "Install Apache for LNMP V1.0  ,  Written by Licess \n"printf "=======================================================================\n"printf "LNMP is a tool to auto-compile & install Nginx+MySQL+PHP on Linux \n"printf "This script is a tool to install Apache for lnmp \n"printf "\n"printf "For more information please visit http://www.lnmp.org \n"printf "=======================================================================\n"#把當前路徑給變數cur_dircur_dir=$(pwd)#這個重點說一下,察看ip,#通過1次grep,過濾掉不包含inet的行#2次反向grep也就是取不包含的行,過濾掉包含127.0.0.1和inet6的行#awk 列印第2列#tr -d 去掉addr:,這樣就只剩下ipipv4=`ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v inet6|awk '{print $2}'|tr -d "addr:"`#set Server Administrator Email Address    ServerAdmin=""        #讀取使用者鍵盤輸入還可以使用-t 30 指定時間限制    read -p "Please input Administrator Email Address:" ServerAdmin    if [ "$ServerAdmin" == "" ]; then        echo "Administrator Email Address will set to webmaster@example.com!"        ServerAdmin="webmaster@example.com"    else    echo "==========================="    echo Server Administrator Email="$ServerAdmin"    echo "==========================="    fi        #定義函數    get_char()    {        #列印當前終端的設定賦予變數    SAVEDSTTY=`stty -g`        #echo input characters    stty -echo    stty cbreak        #把指定的輸入檔案拷貝到指定的輸出檔案中,並且在拷貝的過程中可以進行格式轉換        #if =輸入檔案,bs = bytes 同時設定讀/寫緩衝區的位元組數(等於設定obs和ibs),count = blocks 只拷貝輸入的blocks塊    dd if=/dev/tty bs=1 count=1 2> /dev/null    stty -raw    stty echo    stty $SAVEDSTTY    }    echo ""    echo "Press any key to start install Apache for LNMP or Press Ctrl+C to cancel..."    char=`get_char`printf "===================== Check And Download Files =================\n"#test測試 如果檔案的長度不為零,則為真if [ -s httpd-2.2.22.tar.gz ]; then  echo "httpd-2.2.22.tar.gz [found]"  else  echo "Error: httpd-2.2.22.tar.gz not found!!!download now......"  wget -c http://soft.vpser.net/web/apache/httpd-2.2.22.tar.gzfi#mod_rpaf是apache的一個模組,目的是為了擷取訪客的真實IPif [ -s mod_rpaf-0.6.tar.gz ]; then  echo "mod_rpaf-0.6.tar.gz [found]"  else  echo "Error: mod_rpaf-0.6.tar.gz not found!!!download now......"  wget -c http://soft.vpser.net/web/apache/rpaf/mod_rpaf-0.6.tar.gzfi#php源碼if [ -s php-5.2.17.tar.gz ]; then  echo "php-5.2.17.tar.gz [found]"  else  echo "Error: php-5.2.17.tar.gz not found!!!download now......"  wget -c http://soft.vpser.net/web/php/php-5.2.17.tar.gzfiprintf "=========================== install Apache ======================\n"#停止當前的其他服務echo "Stoping Nginx..."/etc/init.d/nginx stopecho "Stoping MySQL..."/etc/init.d/mysql stopecho "Stoping PHP-FPM..."/etc/init.d/php-fpm stopif [ -s /etc/init.d/memceached ]; then  echo "Stoping Memcached..."  /etc/init.d/memcacehd stopfi#備份echo "Backup old php configure files....."mkdir /root/lnmpbackup/cp /root/lnmp /root/lnmpbackup/cp /usr/local/php/etc/php.ini /root/lnmpbackup/cp /usr/local/php/etc/php-fpm.conf /root/lnmpbackup/#開始編譯安裝cd $cur_dirrm -rf httpd-2.2.22/tar zxvf httpd-2.2.22.tar.gzcd httpd-2.2.22/./configure --prefix=/usr/local/apache --enable-headers --enable-mime-magic --enable-proxy --enable-so --enable-rewrite --enable-ssl --enable-deflate --enable-suexec --disable-userdir --with-included-apr --with-mpm=prefork --with-ssl=/usr --disable-userdir --disable-cgid --disable-cgi --with-expat=builtinmake && make installcd ..mv /usr/local/apache/conf/httpd.conf /usr/local/apache/conf/httpd.conf.bak#\cp 不走alias的cp\cp $cur_dir/conf/httpd.conf /usr/local/apache/conf/httpd.conf\cp $cur_dir/conf/httpd-default.conf /usr/local/apache/conf/extra/httpd-default.conf\cp $cur_dir/conf/httpd-vhosts.conf /usr/local/apache/conf/extra/httpd-vhosts.conf\cp $cur_dir/conf/httpd-mpm.conf /usr/local/apache/conf/extra/httpd-mpm.conf\cp $cur_dir/conf/rpaf.conf /usr/local/apache/conf/extra/rpaf.conf#sed實現內容替換sed -i 's/#ServerName www.example.com:80/ServerName www.lnmp.org:88/g' /usr/local/apache/conf/httpd.confsed -i 's/ServerAdmin you@example.com/ServerAdmin '$ServerAdmin'/g' /usr/local/apache/conf/httpd.conf#sed -i 's/www.lnmp.org/'$domain'/g' /usr/local/apache/conf/extra/httpd-vhosts.confsed -i 's/webmaster@example.com/'$ServerAdmin'/g' /usr/local/apache/conf/extra/httpd-vhosts.confmkdir -p /usr/local/apache/conf/vhost#向/usr/local/apache/conf/httpd.conf中末尾追加內容Include conf/vhost/*.confcat >>/usr/local/apache/conf/httpd.conf<<EOFInclude conf/vhost/*.confEOF#安裝rpaftar -zxvf mod_rpaf-0.6.tar.gzcd mod_rpaf-0.6//usr/local/apache/bin/apxs -i -c -n mod_rpaf-2.0.so mod_rpaf-2.0.ccd ..#建立軟鏈ln -s /usr/local/lib/libltdl.so.3 /usr/lib/libltdl.so.3#sed -i 's#your_ips#'$ipv4'#g' /usr/local/apache/conf/extra/rpaf.confecho "Stop php-fpm....."rm -rf /usr/local/php/cd $cur_dirif [ -s php-5.2.17 ]; thenrm -rf php-5.2.17fitar zxvf php-5.2.17.tar.gzcd php-5.2.17/wget -c http://soft.vpser.net/web/php/bug/php-5.2.17-max-input-vars.patch#打一個補丁這裡需要瞭解diff和patchpatch -p1 < php-5.2.17-max-input-vars.patch./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-apxs2=/usr/local/apache/bin/apxs --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-discard-path --enable-magic-quotes --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-mbstring --with-mcrypt --enable-ftp --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --with-mime-magicif cat /etc/issue | grep -Eqi '(Debian|Ubuntu)';then    cd ext/openssl/    wget -c http://soft.vpser.net/lnmp/ext/debian_patches_disable_SSLv2_for_openssl_1_0_0.patch    patch -p3 <debian_patches_disable_SSLv2_for_openssl_1_0_0.patch    cd ../../firm -rf libtoolcp /usr/local/apache/build/libtool .make ZEND_EXTRA_LIBS='-liconv'make installmkdir -p /usr/local/php/etccp php.ini-dist /usr/local/php/etc/php.inicd ../#安裝PDO擴充cd $cur_dir/php-5.2.17/ext/pdo_mysql//usr/local/php/bin/phpize./configure --with-php-config=/usr/local/php/bin/php-config --with-pdo-mysql=/usr/local/mysqlmake && make installcd $cur_dir/# 添加 php extensionssed -i 's#extension_dir = "./"#extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/"\nextension = "memcache.so"\nextension = "pdo_mysql.so"\n#' /usr/local/php/etc/php.inised -i 's#output_buffering = Off#output_buffering = On#' /usr/local/php/etc/php.inised -i 's/post_max_size = 8M/post_max_size = 50M/g' /usr/local/php/etc/php.inised -i 's/upload_max_filesize = 2M/upload_max_filesize = 50M/g' /usr/local/php/etc/php.inised -i 's/;date.timezone =/date.timezone = PRC/g' /usr/local/php/etc/php.inised -i 's/short_open_tag = Off/short_open_tag = On/g' /usr/local/php/etc/php.inised -i 's/; cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/g' /usr/local/php/etc/php.inised -i 's/max_execution_time = 30/max_execution_time = 300/g' /usr/local/php/etc/php.inised -i 's/disable_functions =.*/disable_functions = passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,pfsockopen,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,fsocket,fsockopen/g' /usr/local/php/etc/php.ini#根據系統安裝ZendOptimizerif [ `getconf WORD_BIT` = '32' ] && [ `getconf LONG_BIT` = '64' ] ; then        wget -c http://soft.vpser.net/web/zend/ZendOptimizer-3.3.9-linux-glibc23-x86_64.tar.gz        tar zxvf ZendOptimizer-3.3.9-linux-glibc23-x86_64.tar.gz    mkdir -p /usr/local/zend/    cp ZendOptimizer-3.3.9-linux-glibc23-x86_64/data/5_2_x_comp/ZendOptimizer.so /usr/local/zend/else        wget -c http://soft.vpser.net/web/zend/ZendOptimizer-3.3.9-linux-glibc23-i386.tar.gz    tar zxvf ZendOptimizer-3.3.9-linux-glibc23-i386.tar.gz    mkdir -p /usr/local/zend/    cp ZendOptimizer-3.3.9-linux-glibc23-i386/data/5_2_x_comp/ZendOptimizer.so /usr/local/zend/fi#給php.ini追加內容cat >>/usr/local/php/etc/php.ini<<EOF;eaccelerator;ionCube[Zend Optimizer]zend_optimizer.optimization_level=1zend_extension="/usr/local/zend/ZendOptimizer.so"EOFcd $cur_dircp conf/proxy.conf /usr/local/nginx/conf/proxy.confmv /usr/local/nginx/conf/nginx.conf /root/lnmpbackup/cp conf/nginx_a.conf /usr/local/nginx/conf/nginx.conf#添加apache自動啟動指令碼echo "Download new Apache init.d file......"wget -c http://soft.vpser.net/lnmp/ext/init.d.httpdcp init.d.httpd /etc/init.d/httpdchmod +x /etc/init.d/httpdecho "Test Nginx configure files..."/usr/local/nginx/bin/nginx -techo "ReStarting Nginx......"/etc/init.d/nginx restartecho "Starting Apache....."/etc/init.d/httpd restart#更新系統啟動項echo "Remove old startup files and Add new startup file....."if cat /etc/issue | grep -Eqi '(Debian|Ubuntu)';then    update-rc.d -f httpd defaults    update-rc.d -f php-fpm removeelse    sed -i '/php-fpm/'d /etc/rc.local    chkconfig --level 345 php-fpm off    chkconfig --level 345 httpd onficd $cur_dirrm -f /etc/init.d/php-fpmmv /root/vhost.sh /root/lnmp.vhost.shcp vhost_lnmpa.sh /root/vhost.shchmod +x /root/vhost.shcp lnmpa /root/chmod +x /root/lnmpaprintf "====================== Upgrade to LNMPA completed =====================\n"printf "You have successfully upgrade from lnmp to lnmpa,enjoy it!\n"printf "=======================================================================\n"printf "LNMP is a tool to auto-compile & install Nginx+MySQL+PHP on Linux \n"printf "This script is a tool to upgrade from lnmp to lnmpa \n"printf "\n"printf "For more information please visit http://www.lnmp.org \n"printf "=======================================================================\n"


本文出自 “phper” 部落格,請務必保留此出處http://janephp.blog.51cto.com/4439680/1302196

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.