Analyze the apache. sh script in the lnmp installation package

Source: Internet
Author: User

Analyze shell scripts and learn how to install apache in lnmp environment to implement lnmpa environment.

#! /Bin/bash # define the PATH variable PATH =/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin: ~ /Bin # declare PATH as the environment variable export PATH # Check if user is root # id-u uid of the current user. You can also use the back quotation marks 'id-U'. The effect is the same, 0 is root user idif [$ (id-u )! = "0"]; then echo "Error: You must be root to run this script, please use root to install lnmp "exit 1fi # clear screen operation clear # special characters can be recognized printf" ================ ========================================================== =============\ n "printf" Install Apache for LNMP V1.0, written by Licess \ n "printf" ============================== ========================================================= \ n "printf" LNMP is a tool to auto-compile & install Ngin X + 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 "# path to the variable cur_dircur_dir = $ (pwd) # Check the ip address. # Use grep once to filter out rows that do not contain inet. # Use reverse grep twice to retrieve rows that do not contain inet, filter out the rows that contain 127.0.0.1 and inet6 # awk prints 2nd columns # tr-d removes addr:, so that only 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 =" "# You can use-t 30 to specify the time limit for reading user keyboard input." 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 # define a function get_char () {# print the settings of the current terminal and assign the variable SAVEDSTTY = 'stty-G' # echo input characters stty-echo stty cbreak # copy the specified input file to the specified output file, in addition, the format can be converted during the copy process # if = input file, bs = bytes simultaneously set the number of bytes in the read/write buffer (equal to setting obs and ibs ), count = blocks copy only the input blocks block dd if =/dev/tty bs = 1 c Ount = 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 the file length is not zero, true 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 pipeline [-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 pipeline [-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 "# Stop other current services 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 # backup e Cho "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/# start compiling and installing cd $ cur_dirrm-rf httpd-2.2.22/tar zxvf httpd-2.2.22.tar.gzcd /. /configure -- prefix =/usr/local/apache -- enable-headers -- enable-mime-magic -- enable-proxy -- enable-so -- enable-rewrite -- en Able-ssl -- enable-deflate -- enable-suexec -- disable-userdir -- with-encoded-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 does not go through 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 implement content replacement sed-I's/# ServerName www.example.com: 80/ServerName www.lnmp.org: 88/G'/usr/local/apache/conf/httpd. confsed-I's/ServerAdmi N 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 # To/usr/local/apache/conf/httpd. include conf/vhost /*. confcat>/usr/local/apache/conf/httpd. c Onf <EOFInclude conf/vhost /*. confEOF # Install 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 .. # create a soft link 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 p Hp-5.2.17.tar.gzcd php-5.2.17/wget-c connector-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-di R -- 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. ma Ke ZEND_EXTRA_LIBS = '-liconv' make installmkdir-p/usr/local/php/etccp php. ini-dist/usr/local/php/etc/php. inicd .. /# Install PDO extension 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 /# Add 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 = 8 M/post_max_size = 50 M/G'/usr/local/php/etc/php. inised-I's/upload_max_filesize = 2 M/upload_max_filesize = 50 M/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, sh Ell_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 # Install 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 according to the system .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 # For php. ini Append content 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 # Add the apache Automatic startup script echo "Download new Apache ini T. 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 # update the system startup Item echo "Remove old startup files and Add new startup file ..... "if cat/etc/issue | grep-Eqi '(Deb Ian | 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 complet Ed =================================\ 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"


This article is from the "phper" blog, please be sure to keep this source http://janephp.blog.51cto.com/4439680/1302196

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.