php环境一键升级脚本

  因为要解析PHP页面需要配置相应的PHP环境,而系统本身的php版本又大多不合适。网上那种一键lamp和lnmp的脚本很多,但是这样一来自己能够定制的空间则少了。所以我自己编写了个门用于安装php环境的脚本!

 

脚本内容:

  

#!/bin/bash

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

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

        exit 1

fi

read -p "Are you 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 install wget before install"

        exit 3

fi

while true;do

read -p "Please input which version of PHP do you want to install like x.x.x:" version

if [[ $version =~ ^[0-9]\.[0-9]\.[0-9]$ ]];then

        wget museum.php.net/php${version:0:1}/php-${version}.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  libicu-devel -y

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

cd ./php-${version}

./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  --enable-intl

make && make install

if [ $? == 0 ];then

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

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

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

cd ..

rm -rf php-${version}*

else

cd ..

rm -rf php-${version}*

echo -e "\033[5;31mCompilation install failed!\033[0m"

fi

;;

[Nn])

        echo "Install aborting!"

        exit 4

;;

esac

  

 

 

 

转载于:https://www.cnblogs.com/RottenLeaf/p/9650700.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值