1. 程式人生 > >php環境一鍵升級腳本

php環境一鍵升級腳本

end error: resolve max bzip2 env conn mat ESS

  因為要解析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

  

php環境一鍵升級腳本