Analysis shell script, learning method, this is actually in the LNMP environment to install Apache, realize LNMPA environment.
#!/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 the UID of the current user, or you can use the inverted quote ' id-u ', the same effect, 0 user ID if [$ (id-u)!= "0"]; Then echo "Error:you must is root to run the script, please use the root to install LNMP" Exit 1 fi #清屏操作 Clear #可以识 Special character printf "=======================================================================\n" printf "Install Apache for Lnmp V1.0, written by licess \ n "printf" =======================================================================\n "PR Intf "LNMP is a tool to Auto-compile & Install on Linux \ n" printf "This script are a nginx+mysql+php to tool a Pache for LNMP \ n "printf" \ n "printf" For further information please visit http://www.lnmp.org \ n "printf" ================= ======================================================\n "#把当前路径给变量cur_dir cur_dir=$ (PWD) #这个重点说一下, viewing IP, #通过1次grep , filter out rows #2次反向grep也就是取不包含的行 that do not contain inet, filter out rows containing 127.0.0.1 and Inet6 #awk print the 2nd column
#tr-D removes addr: This leaves only IP ipv4= ' ifconfig-a|grep inet|grep-v 127.0.0.1|grep-v ' {print $} ' Inet6|awk ' |tr-d: ' #set Server Administrator Email Address serveradmin= "#读取用户键盘输入还可以使用-T 30 specify time limit read-p" please input Adminis Trator Email Address: "ServerAdmin if [" $ServerAdmin "="];
Then echo "Administrator Email address would set to webmaster@example.com!" serveradmin= "webmaster@example.com" Else echo "===========================" echo Server Administrator email= "$ ServerAdmin "echo" =========================== "fi #定义函数 Get_char () {#打印当前终端的设置赋予变量 S avedstty= ' stty-g ' #echo input characters stty-echo stty Cbreak #把指定的输入文件拷贝到指定的输出文件中, and can be entered in the process of copying Row format Conversion #if = input file, bs = bytes Sets the number of bytes in the read/write buffer (equal to setting up Obs and IBS), Count = blocks copy-only blocks block 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测试 true if [-s httpd-2.2.22.tar.gz] if the length of the file is not zero; 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.gz fi #mod_rpaf是apache的一个模块, The purpose is to obtain the true IP if [-s mod_rpaf-0.6.tar.gz] of the visitor; 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.gz fi #php源码 If [-s PHP-5.2.17.TAR.G Z]; 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.gz fi printf" =========================== Install Apache ======================\n "#停止当前的其他服务 echo" stoping Nginx ... "/etc/init.d/nginx stop echo" SToping MySQL ... "/etc/init.d/mysql stop echo" stoping php-fpm ... "/etc/init.d/php-fpm stop if [-s/etc/init.d/memceached ]; Then echo "stoping Memcached ..."/etc/init.d/memcacehd stop fi #备份 echo "Backup old php Configure Files ..." mkdir/r oot/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 _dir rm-rf httpd-2.2.22/tar zxvf httpd-2.2.22.tar.gz cd httpd-2.2.22/./co nfigure--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
usr--disable-userdir--disable-cgid--disable-cgi--with-expat=builtin make && make install CD. The CP \cp $cur Mv/usr/local/apache/conf/httpd.conf/usr/local/apache/conf/httpd.conf.bak #\cp does not take the alias _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.conf sed-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.conf sed-i ' s/webmaster@example.com/' $ServerAdmin '/g '/usr/local/apache/conf/extra/ httpd-vhosts.conf mkdir-p/usr/local/apache/conf/vhost #向/usr/local/apache/conf/httpd.conf append content include conf/ vhost/*.conf cat >>/usr/local/apache/conf/httpd.conf<<eof Include conf/vhost/*.conf EOF #安装rpaf TAR-ZXVF mod_rpaf-0.6.tar.gz CD mod_rpaf-0.6//usr/local/apache/bin/apxs-i-c-n mod_rpaf-2.0.so mod_rpaf-2.0.c CD. #创建软链 ln-s/usr/local/lib/libltdl.so.3/usr/lib/libltdl.so.3 #sed-i ' s#your_ips# ' $IPV 4 ' #g '/usr/local/apache/conf/ extra/rpaf.conf echo "Stop php-fpm ..." rm-rf/usr/local/php/cd $cur _dir if [-s php-5.2.17]; Then Rm-rf php-5.2.17 fi tar zxvf php-5.2.17.tar.gz cd php-5.2.17/wget-c http://soft.vpser.net/web/php/bug/php-5.2.17-m Ax-input-vars.patch #打一个补丁这里需要了解diff和patch Patch-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-- Enable-zip--enable-soap--without-pear--with-gettext--with-mime-magic if 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. /..
/fi rm-rf Libtool Cp/usr/local/apache/build/libtool. Make zend_extra_libs= '-liconv ' make install MKDIR-P/usr/local/php/etc CP Php.ini-dist/usr/local/php/etc/php.ini CD. /#安装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/mysql make && make install CD $cur _dir/# Add PHP extensions Sed-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.ini sed-i ' s#output_buffering = off#output_buffering = on# '/usr/local/php/etc/php.ini Sed-i ' s/post_max_size = 8m/post_max_size = 50m/g '/usr/local/php/etc/php.ini sed-i ' s/upload_max_filesize = 2M/upload_m Ax_filesize = 50m/g '/usr/local/php/etc/php.ini sed-i ' s/;d ate.timezone =/date.timezone = PRC/g '/usr/local/php/etc/php . ini sed-i ' s/short_open_tag = Off/short_open_tag = on/g '/usr/local/php/etc/php.ini sed-i ' s/; Cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/g '/usr/local/php/etc/php.ini sed-i ' s/max_execution_time = 30/max_execution_ Time = 300/g '/usr/local/php/etc/php.ini sed-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 #根据系统安装ZendOptimizer If [' getconf word_bit ' = '] && [' 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 zendo ptimizer-3.3.9-linux-glibc23-x86_64.tar.gz mkdir-p/USR/LOCAL/ZEND/CP zendoptimizer-3.3.9-linux-glibc23-x86_64/d Ata/5_2_x_comp/zendoptimizer.so/usr/local/zend/else wget-c Http://soft.vpser.net/web/zend/ZendOptimizer-3.3.9-l Inux-glibc23-i386.tar.gz tar zxvf zendoptimizer-3.3.9-linux-glibc23-i386.tar.gz mkdir-p/usr/local/zend/cp Z Endoptimizer-3.3.9-linux-glibc23-i386/data/5_2_x_comp/zendoptimizer.so/usr/local/zend/fi #给php. ini Append content cat > >/usr/local/php/etc/php.ini<<eof eaccelerator; Ioncube [Zend Optimizer] Zend_optimizer.optimization_level =1 zend_extension= "/usr/local/zend/zendoptimizer.so" EOF CD $cur _dir CP conf/proxy.conf/usr/local/nginx/conf/ proxy.conf MV/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.httpd cp init.d.httpd/etc/init.d/httpd chmod +x/etc/init d/httpd echo "Test Nginx Configure Files ..."/usr/local/nginx/bin/nginx-t Echo restarting Nginx ... "/etc/init.d/ngi NX Restart echo "Starting Apache ..."/etc/init.d/httpd restart #更新系统启动项 echo "Remove old startup files and Add New start Up file ... "If Cat/etc/issue | Grep-eqi ' (debian| Ubuntu) '; then update-rc.d-f httpd defaults update-rc.d-f php-fpm Remove Else sed-i '/php-fpm/' D/etc/rc.loc Al chkconfig--level 345 php-fpm off Chkconfig--level 345 httpd on fi cd $cur _dir rm-f/etc/init.d/php-fpm mv/r oot/vhost.sh/root/lnmp.vhost.sh CP vhost_lnmpa.sh/root/vhost.sh chmod +x/root/vhost.sh CP lnmpa/root/chmod +x/root/l Nmpa printf "====================== Upgrade to Lnmpa completed =====================\n" printf "for you have successfully upgr Ade 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 SCRI PT is a tool to upgrade from LNMP to Lnmpa \ n "printf" \ n "printf" For more information/visit http://www.lnmp.org \ N "printf" =======================================================================\n "
This article comes from "phper-every day a little ~" blog, please be sure to keep this source http://janephp.blog.51cto.com/4439680/1302196
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/OS/Linux/