阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

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

226次阅读
没有评论

共计 6695 个字符,预计需要花费 17 分钟才能阅读完成。

脚本实现自动化 (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
#Date 2017/1/18
#mail xuel@51idc.com
 
[$(id -u) != “0” ] && echo “Error: You must be root to run this script” && exit 1
export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
which  ntpdate
if [$? -eq 0];then
    ntpdate time1.aliyun.com
else
    yum install ntpdate
    ntpdate time1.aliyun.com
fi
yum remove `yum list installed | grep php` -y
clear
if [-n “`grep ‘CentOS Linux release 7’ /etc/RedHat-release`”];then
        CentOS_REL=el7
        rpm -ivh http://repo.webtatic.com/yum/el7/epel-release.rpm
        ls /etc/yum.repos.d/webtatic.repo
        if [$? -eq 0];then
            sed -i “s/#baseurl=/baseurl=/g” /etc/yum.repos.d/webtatic.repo
            sed -i “s/mirrorlist=/#mirrorlist=/g” /etc/yum.repos.d/webtatic.repo
        fi
elif [-n “`grep ‘CentOS release 6’ /etc/redhat-release`”];then
        CentOS_REL=6
        rpm -ivh http://repo.webtatic.com/yum/el6/latest.rpm
    if [$? -eq 0];then
        sed -i “s/#baseurl=/baseurl=/g” /etc/yum.repos.d/webtatic.repo
        sed -i “s/mirrorlist=/#mirrorlist=/g” /etc/yum.repos.d/webtatic.repo
    fi
elif [-n “`grep ‘CentOS release 5’ /etc/redhat-release`”];then
        CentOS_REL=5
        rpm -ivh http://repo.webtatic.com/yum/el5/latest.rpm
    if [$? -eq 0];then
        sed -i “s/#baseurl=/baseurl=/g” /etc/yum.repos.d/webtatic.repo
        sed -i “s/mirrorlist=/#mirrorlist=/g” /etc/yum.repos.d/webtatic.repo
    fi
else
        echo -e “\033[31mDoes not support this OS, Please contact the author! \033[0m”
        exit 1
fi
clear
echo “##########################################”
echo “#                                          #”
echo “#  Auto 编译安装 PHP5.5/5.6/7.0/7.1.    #”
echo “#                                          #”
echo “##########################################”
echo “1 Install PHP-5.5”
echo “2 Install PHP-5.6”
echo “3 Install PHP-7.0”
echo “4 Install PHP-7.1”
echo “5 EXIT”
read -p “Please input your choice:” I
if [“$I” == “1”];then
    VER=”php55w”
elif [“$I” == “2”];then
    VER=”php56w”
elif [“$I” == “3”];then
    VER=”php70w”
elif [“$I” == “4”];then
    VER=”php71w”
elif [“$I” == “5”];then
        echo “you choce channel!”
        exit 1;
else
        echo “input Error! Place input{1|2|3|4|5}”
        exit 0;
fi
clear
echo -e “\033[32m You choice install $VER.Install\033[0m”
echo -e “\033[32m Press any key to start install $VER… \033[0m”
read -n 1
ls /etc/yum.repos.d/webtatic.repo
if [$? -eq 0];then
        yum -y install `yum list|grep php71w|awk ‘{printf (“%s “,$1)}’` –skip-broken
fi
chkconfig php-fpm on
service php-fpm start /tmp/php-install.log 2>&1
STAT=`echo $?`
PORT=`netstat -lntup|grep php-fpm|wc -l`
if [$STAT -eq 0] && [$PORT -eq 1];then
    echo -e “\033[32m PHP is install success! \033[0m”
else
    echo -e “\033[32m PHP install file.please check /tmp/php-install.log \033[0m”
fi

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

#!/bin/bash
#Date 2017/1/10
#mail xuel@51idc.com
[$(id -u) != “0” ] && echo “Error: You must be root to run this script” && exit 1
export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
clear
echo “##########################################”
echo “#                                          #”
echo “#  Auto yum 安装 PHP5.5/5.6/7.0/7.1      #”
echo “#                                          #”
echo “##########################################”
echo “1 Install PHP-5.5.38”
echo “2 Install PHP-5.6.29”
echo “3 Install PHP-7.0.14”
echo “4 Install PHP-7.1.0”
echo “5 EXIT”
read -p “Please input your choice:” I
if [“$I” == “1”];then
        URL=”http://cn2.php.net/distributions/php-5.5.38.tar.gz”
    VER=”php-5.5.38″
elif [“$I” == “2”];then
        URL=”http://cn2.php.net/distributions/php-5.6.29.tar.gz”
    VER=”php-5.6.29″
elif [“$I” == “3”];then
        URL=”http://cn2.php.net/distributions/php-7.0.14.tar.gz”
    VER=”php-7.0.14″
elif [“$I” == “4”];then
        URL=”http://cn2.php.net/distributions/php-7.1.0.tar.gz”
    VER=”php-7.1.0″
elif [“$I” == “5”];then
        echo “you choce channel!”
        exit 1;
else
        echo “input Error! Place input{1|2|3|4|5}”
        exit 0;
fi
read -p “Please input php install dirname:(example:/data/php)” DIR
if [! -d $DIR];then
        mkdir -p $DIR
fi
if [$? -eq 1];then
        echo “$DIR fail! Please intput ture dirname.”
        exit 1
fi
clear
echo -e “\033[32m You choice install $VER.Install dirname:$DIR \033[0m”
echo -e “\033[32m Press any key to start install $VER… \033[0m”
read -n 1
 
which tar >/dev/null 2>&1
if [$? -eq 0];then
    echo “tar is installed”>/tmp/php-install.log
else
    yum install tar -y >/dev/null 2>&1
fi
TDIR=”/tools”
yum install -y wget autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5-devel openssl openssl-devel openldap openldap-devel nss_ldap libXpm* gcc gcc-c++ bison git ntpdate
ntpdate ntpdate time1.aliyun.com >/dev/null 2>&1
if [! -d $TDIR];then
        /bin/mkdir $TDIR && cd $TDIR
fi
/usr/bin/wget -c -O $TDIR/$VER.tar.gz $URL
if [$? -eq 0];then
        tar -zxvf $TDIR/$VER.tar.gz -C $TDIR
else
        yum install tar -y >/dev/null 2>&1
        tar -zxvf $TDIR/$VER.tar.gz >/dev/null 2>&1
fi
cd  $TDIR/$VER
if [$? -eq 0];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-gdbm
fi
make && make install >>/tmp/php-install.log 2>&1
if [$? -eq 0];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  /  -name php.ini-production` /data/php/etc/php.ini >>/tmp/php-install.log 2>&1
fi
id www
USER=`echo $?`
if [$USER -eq 1];then
    useradd -s /sbin/nologin www
fi
echo “export PATH=$PATH:$DIR/bin”>>/etc/profile  && source /etc/profile
/etc/init.d/php-fpm >>/tmp/php-install.log 2>&1
STAT=`echo $?`
PORT=`netstat -lntup|grep php-fpm|wc -l`
if [$STAT -eq 0] && [$PORT -eq 1];then
        echo -e “\033[32m $VER is install success! \033[0m”
else
        echo -e “\033[32m $VER install file.please check /tmp/php-install.log \033[0m”
fi

PHP 7,你值得拥有  http://www.linuxidc.com/Linux/2015-06/118847.htm 

在 CentOS 7.x / Fedora 21 上面体验 PHP 7.0  http://www.linuxidc.com/Linux/2015-05/117960.htm 

CentOS 6.3 安装 LNMP (PHP 5.4,MyySQL5.6) http://www.linuxidc.com/Linux/2013-04/82069.htm 

在部署 LNMP 的时候遇到 Nginx 启动失败的 2 个问题 http://www.linuxidc.com/Linux/2013-03/81120.htm 

Ubuntu 安装 Nginx php5-fpm MySQL(LNMP 环境搭建) http://www.linuxidc.com/Linux/2012-10/72458.htm 

《细说 PHP》高清扫描 PDF+ 光盘源码 + 全套教学视频 http://www.linuxidc.com/Linux/2014-03/97536.htm 

CentOS 6 中配置 PHP 的 LNMP 的开发环境  http://www.linuxidc.com/Linux/2013-12/93869.htm 

PHP 的详细介绍:请点这里
PHP 的下载地址:请点这里

本文永久更新链接地址:http://www.linuxidc.com/Linux/2017-02/140967.htm

正文完
星哥玩云-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-21发表,共计6695字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中