php环境一键升级脚本

#!/bin/bash

if [ $(id -u) != 0 ] ;then

        echo "ERROR: you must be root to run this script"

        exit 1

fi

read -p "Are ready to installing the new PHP environment ?you can input 'y|Y' to continue or 'n|N' to exit." choice

case $choice in

[Yy])

echo "The setup program is preparing,please wait a minute........"

ping -c 4 museum.php.net &> /dev/null

if [ $? != 0 ];then

        echo "Can't connected to the internet or can't resolve domain name,please check your network"

        exit 2

fi

yum install epel-release -y

which wget &> /dev/null

if [ $? != 0 ];then

        echo "wget not exist,please be ensure installed wget before install"

        exit 3

fi

while true;do

read -p "Please input which version of PHP do you want to install:" firstname                                         #输入大版本号

        read -p "Please input the specific version like x.x.x:" secondname   #输入详细版本号

if grep [[:digit:]] <<< ${firstname:0:1} &> /dev/null;then

        wget museum.php.net/php${firstname:0:1}/php-${secondname}.tar.gz

        if [ $? != 0 ] ;then

                echo "You choose a wrong version of PHP,please input another version for install^-^!"

                exit 8

        fi

        break

else

        echo "Please input correct version of number"

fi

done

echo "Start to installing dependent environment!"

        sleep 3

yum install  openssl openssl-devel curl curl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel pcre pcre-devel libxslt libxslt-devel bzip2 bzip2-devel gcc gcc-c++ libxml2 libxml2-devel bzip2 bzip2-devel libmcrypt libmcrypt-devel openssl openssl-devel libcurl-devel libjpeg-devel libpng-devel freetype-devel readline readline-devel libxslt-devel perl perl-devel psmisc.x86_64 recode recode-devel libtidy libtidy-devel  -y

tar -xf php-${secondname}.tar.gz

cd ./php-${secondname}

./configure --prefix=/usr/local/php --with-curl --with-freetype-dir --with-gd --with-gettext --with-iconv-dir --with-kerberos --with-libdir=lib64 --with-libxml-dir --with-mysqli --with-openssl --with-pcre-regex --with-pdo-mysql --with-pdo-sqlite --with-pear --with-png-dir --with-jpeg-dir --with-xmlrpc --with-xsl --with-zlib --with-bz2 --with-mhash --enable-fpm --enable-bcmath --enable-libxml --enable-inline-optimization --enable-gd-native-ttf --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-sysvshm --enable-xml --enable-zip 

make && make install

cp php.ini-development /usr/local/php/lib/php.ini

sed -i 's/post_max_size.*/post_max_size = 16M/' /usr/local/php/lib/php.ini

sed -i 's/max_execution_time.*/max_execution_time = 300/' /usr/local/php/lib/php.ini

sed -i 's/max_input_time.*/max_input_time  = 300/' /usr/local/php/lib/php.ini

sed -i 's/;mbstring.func_overload = 0/mbstring.func_overload = 0/' /usr/local/php/lib/php.ini

sed -i 's/;always_populate_raw_post_data = -1/always_populate_raw_post_data = -1/' /usr/local/php/lib/php.ini

sed -i 's/;date.timezone.*/date.timezone = Asia\/Shanghai/' /usr/local/php/lib/php.ini

cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf

cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf

cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm

chmod +x /etc/init.d/php-fpm

touch /etc/profile.d/php.sh

echo "export PATH=\$PATH:/usr/local/php/bin" >> /etc/profile

echo -e "php-${filename} has been successfully installed!\nif you want import the php to environmental variables......\nplease executed the command 【source /etc/profile】";;

[Nn])

        echo "Install aborting!"

        exit 4

;;

esac

猜你喜欢

转载自my.oschina.net/u/3849152/blog/1809492