当前位置:网站首页>Analyze apache SH script
Analyze apache SH script
2022-06-29 22:15:00 【Brother Xing plays with the clouds】
analysis shell Script , Learning methods , This is in fact lnmp Re installation under environment apache, Realization lnmpa Environmental Science .
#!/bin/bash # Definition PATH Variable PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin # Statement PATH For environment variables export PATH # Check if user is root #id -u Current user's uid, You can also use backquotes `id -u`, The effect is the same ,0 by root Users of id if [ $(id -u) != "0" ]; then echo "Error: You must be root to run this script, please use root to install lnmp" exit 1 fi # Clear screen operation clear # Can recognize special characters 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" # Give the current path to the variable cur_dir cur_dir=$(pwd) # Let's focus on , see ip, # adopt 1 Time grep, Filter out those that do not contain inet The line of #2 Secondary reverse grep That is, take the rows that are not included , Filter out those that contain 127.0.0.1 and inet6 The line of #awk Print page 2 Column #tr -d Get rid of addr:, That's all that's left ip ipv4=`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="" # To read user keyboard input, you can also use -t 30 Specify a time limit read -p "Please input Administrator Email Address:" ServerAdmin if [ "$ServerAdmin" == "" ]; then echo "Administrator Email Address will set to [email protected]!" ServerAdmin="[email protected]" else echo "===========================" echo Server Administrator Email="$ServerAdmin" echo "===========================" fi # Defined function get_char() { # Print the setting of the current terminal and assign variables SAVEDSTTY=`stty -g` #echo input characters stty -echo stty cbreak # Copy the specified input file to the specified output file , And format conversion can be carried out in the process of copying #if = Input file ,bs = bytes At the same time, set read / Number of bytes written to the buffer ( Equal to setting obs and ibs),count = blocks Copy only the entered 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 test If the length of the file is not zero , It is 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 http://soft.vpser.net/web/apache/httpd-2.2.22.tar.gz fi #mod_rpaf yes apache A module of , The purpose is to obtain the authenticity of visitors IP if [ -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.gz fi #php Source code 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.gz fi printf "=========================== install Apache ======================\n" # Stop other current services 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 # Backup 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/ # Start compilation and installation cd $cur_dir rm -rf httpd-2.2.22/ tar zxvf httpd-2.2.22.tar.gz cd 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=builtin make && make install cd .. mv /usr/local/apache/conf/httpd.conf /usr/local/apache/conf/httpd.conf.bak #\cp Don't go alias Of 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.conf sed -i 's/ServerAdmin [email protected]/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/[email protected]/'$ServerAdmin'/g' /usr/local/apache/conf/extra/httpd-vhosts.conf mkdir -p /usr/local/apache/conf/vhost # towards /usr/local/apache/conf/httpd.conf At the end of Include conf/vhost/*.conf cat >>/usr/local/apache/conf/httpd.conf<<EOF Include conf/vhost/*.conf EOF # install 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 .. # Create soft chain 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.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-max-input-vars.patch # To make a patch, you need to know diff and 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 --with-xmlrpc --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 ../ # install PDO Expand 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 to 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_max_filesize = 50M/g' /usr/local/php/etc/php.ini sed -i 's/;date.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 # According to the system installation ZendOptimizer if [ `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 # to php.ini Additional 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 # add to apache Auto start script 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/nginx restart echo "Starting Apache....." /etc/init.d/httpd restart # Update system startup items 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 remove else sed -i '/php-fpm/'d /etc/rc.local chkconfig --level 345 php-fpm off chkconfig --level 345 httpd on fi cd $cur_dir rm -f /etc/init.d/php-fpm mv /root/vhost.sh /root/lnmp.vhost.sh cp vhost_lnmpa.sh /root/vhost.sh chmod +x /root/vhost.sh cp lnmpa /root/ chmod +x /root/lnmpa printf "====================== 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"
边栏推荐
- American tunneling ASTM E84 surface flame retardant test
- STM32 and gd32 notes
- 华为7年经验的软件测试总监,给所有想转行学软件测试的同学的几个建议
- ASP.NET 跨页面提交(Button控件页面重定向)
- Summer Challenge harmonyos ark development framework arkui streamer button effect
- Automatic reply of wechat bulletin number intelligent reply with Turing robot
- leetcode:91. 解码方法【dfs + 记忆化】
- MooseFS基本概念总结
- The database of the server cannot be connected [the service has been started, the firewall has been closed, the port has been opened, and the netlent port is not connected]
- 便携式4K音视频会议终端一体机带8倍数字变焦
猜你喜欢

ASP利用Panel实现简易注册页面

5分钟快速上手 pytest 测试框架

小型圖書館項目總結

Huawei's software testing director with 7 years' experience, several suggestions for all students who want to switch to software testing

Motianlun "high availability architecture" dry goods document sharing (including 124 Oracle, MySQL and PG materials)

铝板AS/NZS 1530.1 不燃性材料的阻燃测试

Star ring technology data security management platform defender heavy release

一文2500字手把手教你使用jmeter进行分布式压力测试【保姆级教程】

Matlab adds noise / disturbance to data

DevCloud加持下的青软,让教育“智”上云端
随机推荐
Golang operation etcd
每日刷题记录 (八)
Flutter technology and Practice (2)
Wechat bulletin number Turing robot realizes intelligent reply
ASP dynamically creates table table
华为云AOM 2.0版本发布
夏日彩虹来下饭
R language plot visualization: plot to visualize the normalized histograms of multiple data sets, set different histograms to use different bin sizes, and add edge axis whisker graph rugs at the botto
[cloud native] use of Nacos taskmanager task management
Three development trends of enterprise application viewed from the third technological revolution
Alibaba product details API interface (item_get- get product details interface), Alibaba API interface
动态规划学习(持续更新)
Go standard library context package: data, cancellation signal, deadline and other related operations between a single request and multiple goroutines and the request domain
22 years of a doctor in Huawei
Hardware development notes (VIII): basic process of hardware development, making a USB to RS232 module (VII): creating a basic dip component (crystal oscillator) package and associating the principle
Graduation summary of construction practice camp
Is it safe to bind securities accounts to flush? Which securities firm can bind flush after opening an account
客户端可以连接远程mysql
Reading notes on how to connect the network - Web server request and response (V)
Weibo comments on high availability and high performance computing architecture