自动化(YUM/编译)安装PHP(5.3/5.5/7.0/7.1)脚本


PHP(外文名:PHP Hypertext Preprocessor,中文名:“超文本预处理器”)是一种通用开源脚本语言。

它可以比CGI或者Perl更快速地执行动态网页。为方便快安装部署php,可以参考一下脚本。


1.YUM安装PHP(5.3/5.5/7.0/7.1)

#!/bin/bash#Date2017/1/18#mailxuel@51idc.com[$(id-u)!="0"]&&echo"Error:Youmustberoottorunthisscript"&&exit1exportPATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/binwhichntpdateif[$?-eq0];thenntpdatetime1.aliyun.comelseyuminstallntpdatentpdatetime1.aliyun.comfiyumremove`yumlistinstalled|grepphp`-yclearif[-n"`grep'CentOSLinuxrelease7'/etc/redhat-release`"];thenCentOS_REL=el7rpm-ivhhttp://repo.webtatic.com/yum/el7/epel-release.rpmls/etc/yum.repos.d/webtatic.repoif[$?-eq0];thensed-i"s/#baseurl=/baseurl=/g"/etc/yum.repos.d/webtatic.reposed-i"s/mirrorlist=/#mirrorlist=/g"/etc/yum.repos.d/webtatic.repofielif[-n"`grep'CentOSrelease6'/etc/redhat-release`"];thenCentOS_REL=6rpm-ivhhttp://repo.webtatic.com/yum/el6/latest.rpmif[$?-eq0];thensed-i"s/#baseurl=/baseurl=/g"/etc/yum.repos.d/webtatic.reposed-i"s/mirrorlist=/#mirrorlist=/g"/etc/yum.repos.d/webtatic.repofielif[-n"`grep'CentOSrelease5'/etc/redhat-release`"];thenCentOS_REL=5rpm-ivhhttp://repo.webtatic.com/yum/el5/latest.rpmif[$?-eq0];thensed-i"s/#baseurl=/baseurl=/g"/etc/yum.repos.d/webtatic.reposed-i"s/mirrorlist=/#mirrorlist=/g"/etc/yum.repos.d/webtatic.repofielseecho-e"\033[31mDoesnotsupportthisOS,Pleasecontacttheauthor!\033[0m"exit1ficlearecho"##########################################"echo"##"echo"#Auto编译安装PHP5.5/5.6/7.0/7.1.#"echo"##"echo"##########################################"echo"1InstallPHP-5.5"echo"2InstallPHP-5.6"echo"3InstallPHP-7.0"echo"4InstallPHP-7.1"echo"5EXIT"read-p"Pleaseinputyourchoice:"Iif["$I"=="1"];thenVER="php55w"elif["$I"=="2"];thenVER="php56w"elif["$I"=="3"];thenVER="php70w"elif["$I"=="4"];thenVER="php71w"elif["$I"=="5"];thenecho"youchocechannel!"exit1;elseecho"inputError!Placeinput{1|2|3|4|5}"exit0;ficlearecho-e"\033[32mYouchoiceinstall$VER.Install\033[0m"echo-e"\033[32mPressanykeytostartinstall$VER...\033[0m"read-n1ls/etc/yum.repos.d/webtatic.repoif[$?-eq0];thenyum-yinstall`yumlist|grepphp71w|awk'{printf("%s",$1)}'`--skip-brokenfichkconfigphp-fpmonservicephp-fpmstart/tmp/php-install.log2>&1STAT=`echo$?`PORT=`netstat-lntup|grepphp-fpm|wc-l`if[$STAT-eq0]&&[$PORT-eq1];thenecho-e"\033[32mPHPisinstallsuccess!\033[0m"elseecho-e"\033[32mPHPinstallfile.pleasecheck/tmp/php-install.log\033[0m"fi


2.编译安装PHP(5.3/5.5/7.0/7.1)

#!/bin/bash#Date2017/1/10#mailxuel@51idc.com[$(id-u)!="0"]&&echo"Error:Youmustberoottorunthisscript"&&exit1exportPATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/binclearecho"##########################################"echo"##"echo"#Autoyum安装PHP5.5/5.6/7.0/7.1#"echo"##"echo"##########################################"echo"1InstallPHP-5.5.38"echo"2InstallPHP-5.6.29"echo"3InstallPHP-7.0.14"echo"4InstallPHP-7.1.0"echo"5EXIT"read-p"Pleaseinputyourchoice:"Iif["$I"=="1"];thenURL="http://cn2.php.net/distributions/php-5.5.38.tar.gz"VER="php-5.5.38"elif["$I"=="2"];thenURL="http://cn2.php.net/distributions/php-5.6.29.tar.gz"VER="php-5.6.29"elif["$I"=="3"];thenURL="http://cn2.php.net/distributions/php-7.0.14.tar.gz"VER="php-7.0.14"elif["$I"=="4"];thenURL="http://cn2.php.net/distributions/php-7.1.0.tar.gz"VER="php-7.1.0"elif["$I"=="5"];thenecho"youchocechannel!"exit1;elseecho"inputError!Placeinput{1|2|3|4|5}"exit0;firead-p"Pleaseinputphpinstalldirname:(example:/data/php)"DIRif[!-d$DIR];thenmkdir-p$DIRfiif[$?-eq1];thenecho"$DIRfail!Pleaseintputturedirname."exit1ficlearecho-e"\033[32mYouchoiceinstall$VER.Installdirname:$DIR\033[0m"echo-e"\033[32mPressanykeytostartinstall$VER...\033[0m"read-n1whichtar>/dev/null2>&1if[$?-eq0];thenecho"tarisinstalled">/tmp/php-install.logelseyuminstalltar-y>/dev/null2>&1fiTDIR="/tools"yuminstall-ywgetautoconflibjpeglibjpeg-devellibpnglibpng-develfreetypefreetype-devellibxml2libxml2-develzlibzlib-develglibcglibc-develbzip2bzip2-develncursesncurses-develcurlcurl-devele2fsprogse2fsprogs-develkrb5-developensslopenssl-developenldapopenldap-develnss_ldaplibXpm*gccgcc-c++bisongitntpdatentpdatentpdatetime1.aliyun.com>/dev/null2>&1if[!-d$TDIR];then/bin/mkdir$TDIR&&cd$TDIRfi/usr/bin/wget-c-O$TDIR/$VER.tar.gz$URLif[$?-eq0];thentar-zxvf$TDIR/$VER.tar.gz-C$TDIRelseyuminstalltar-y>/dev/null2>&1tar-zxvf$TDIR/$VER.tar.gz>/dev/null2>&1ficd$TDIR/$VERif[$?-eq0];then./configure--prefix=$DIR--exec-prefix=$DIR--bindir=$DIR/bin--sbindir=$DIR/sbin--includedir=$DIR/include--libdir=$DIR/lib/php--mandir=$DIR/php/man--with-config-file-path=$DIR/etc--with-mysql-sock=/tmp/mysql.sock--with-mhash--with-openssl--with-mysql=shared,mysqlnd--with-mysqli=shared,mysqlnd--with-pdo-mysql=shared,mysqlnd--with-gd--with-iconv--with-zlib--enable-zip--enable-inline-optimization--enable-shared--enable-xml--enable-bcmath--enable-shmop--enable-sysvsem--enable-mbregex--enable-mbstring--enable-ftp--enable-gd-native-ttf--enable-pcntl--enable-sockets--with-xmlrpc--enable-soap--without-pear--with-gettext--enable-session--with-curl--with-jpeg-dir--with-freetype-dir--enable-opcache--enable-fpm--enable-fastcgi--with-fpm-user=www--with-fpm-group=www--without-gdbmfimake&&makeinstall>>/tmp/php-install.log2>&1if[$?-eq0];then/bin/cp$DIR/etc/php-fpm.conf.default$DIR/etc/php-fpm.conf&&cp$DIR/etc/php-fpm.d/www.conf.default$DIR/etc/php-fpm.d/www.conf&&cp-R$DIR/sbin/php-fpm/etc/init.d/php-fpm&&/bin/cp`find/-namephp.ini-production`/data/php/etc/php.ini>>/tmp/php-install.log2>&1fiidwwwUSER=`echo$?`if[$USER-eq1];thenuseradd-s/sbin/nologinwwwfiecho"exportPATH=$PATH:$DIR/bin">>/etc/profile&&source/etc/profile/etc/init.d/php-fpm>>/tmp/php-install.log2>&1STAT=`echo$?`PORT=`netstat-lntup|grepphp-fpm|wc-l`if[$STAT-eq0]&&[$PORT-eq1];thenecho-e"\033[32m$VERisinstallsuccess!\033[0m"elseecho-e"\033[32m$VERinstallfile.pleasecheck/tmp/php-install.log\033[0m"fi