#!/bin/bash PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin export PATH # Check if user is root if [ $(id -u) != "0" ]; then echo "Error: You must be root to run this script, please use root to install lnmp" exit 1 fi clear echo "=========================================================================" echo "Upgrade PHP for LNMP, Written by Licess" echo "=========================================================================" echo "LNMP is tool to auto-compile & install Nginx+MySQL+PHP on Linux " echo "" echo "For more information please visit http://www.lnmp.org/" echo "=========================================================================" cur_dir=$(pwd) if [ "$1" != "--help" ]; then old_php_version=`/usr/local/php/bin/php -r 'echo PHP_VERSION;'` #echo $old_php_version if [ -s /usr/local/mariadb/bin/mysql ]; then ismysql="no" else ismysql="yes" fi #set php version php_version="" echo "Current PHP Version:$old_php_version" echo "You can get version number from http://www.php.net/" read -p "(Please input PHP Version you want):" php_version if [ "$php_version" = "" ]; then echo "Error: You must input php version!!" exit 1 fi if [ "$php_version" == "$old_php_version" ]; then echo "Error: The upgrade PHP Version is the same as the old Version!!" exit 1 fi echo "==================================================" echo "You want to upgrade php version to $php_version" echo "==================================================" get_char() { SAVEDSTTY=`stty -g` stty -echo stty cbreak dd if=/dev/tty bs=1 count=1 2> /dev/null stty -raw stty echo stty $SAVEDSTTY } echo "" echo "Press any key to start...or Press Ctrl+c to cancel" char=`get_char` echo "============================check files==================================" if [ -s php-$php_version.tar.gz ]; then echo "php-$php_version.tar.gz [found]" else echo "Error: php-$php_version.tar.gz not found!!!download now......" wget -c http://www.php.net/distributions/php-$php_version.tar.gz if [ $? -eq 0 ]; then echo "Download php-$php_version.tar.gz successfully!" else wget -c http://museum.php.net/php5/php-$php_version.tar.gz if [ $? -eq 0 ]; then echo "Download php-$php_version.tar.gz successfully!" else echo "WARNING!May be the php version you input was wrong,please check!" echo "PHP Version input was:"$php_version sleep 5 exit 1 fi fi fi if [ -s autoconf-2.13.tar.gz ]; then echo "autoconf-2.13.tar.gz [found]" else echo "Error: autoconf-2.13.tar.gz not found!!!download now......" wget -c http://soft.vpser.net/lib/autoconf/autoconf-2.13.tar.gz fi echo "============================check files==================================" echo "Stoping Nginx..." /etc/init.d/nginx stop if [ "$ismysql" = "no" ]; then echo "Stoping MariaDB..." /etc/init.d/mariadb stop else echo "Stoping MySQL..." /etc/init.d/mysql stop fi echo "Stoping PHP-FPM..." /etc/init.d/php-fpm stop if [ -s /etc/init.d/memceached ]; then echo "Stoping Memcached..." /etc/init.d/memcacehd stop fi rm -rf php-$php_version/ if [ -s /usr/local/autoconf-2.13/bin/autoconf ] && [ -s /usr/local/autoconf-2.13/bin/autoheader ]; then echo "check autconf 2.13: OK" else tar zxvf autoconf-2.13.tar.gz cd autoconf-2.13/ ./configure --prefix=/usr/local/autoconf-2.13 make && make install cd ../ fi ln -s /usr/lib/libevent-1.4.so.2 /usr/local/lib/libevent-1.4.so.2 ln -s /usr/lib/libltdl.so /usr/lib/libltdl.so.3 if [ $php_version = "5.2.14" ] || [ $php_version = "5.2.15" ] || [ $php_version = "5.2.16" ] || [ $php_version = "5.2.17" ]; then if [ -s php-$php_version-fpm-0.5.14.diff.gz ]; then echo "php-$php_version-fpm-0.5.14.diff.gz [found]" else echo "Error: php-$php_version-fpm-0.5.14.diff.gz not found!!!download now......" wget -c http://php-fpm.org/downloads/php-$php_version-fpm-0.5.14.diff.gz fi cd $cur_dir echo "Stop php-fpm....." if [ -s /usr/local/php/sbin/php-fpm ]; then /usr/local/php/sbin/php-fpm stop else /etc/init.d/php-fpm stop fi echo "Start install php-$php_version....." export PHP_AUTOCONF=/usr/local/autoconf-2.13/bin/autoconf export PHP_AUTOHEADER=/usr/local/autoconf-2.13/bin/autoheader tar zxvf php-$php_version.tar.gz gzip -cd php-$php_version-fpm-0.5.14.diff.gz | patch -d php-$php_version -p1 cd php-$php_version/ wget -c http://soft.vpser.net/web/php/bug/php-5.2.17-max-input-vars.patch patch -p1 < php-5.2.17-max-input-vars.patch ./buildconf --force if [ "$ismysql" = "no" ]; then ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mariadb --with-mysqli=/usr/local/mariadb/bin/mysql_config --with-pdo-mysql=/usr/local/mariadb --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-discard-path --enable-magic-quotes --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-fastcgi --enable-fpm --enable-force-cgi-redirect --enable-mbstring --with-mcrypt --enable-ftp --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --with-mime-magic else ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-pdo-mysql=/usr/local/mysql --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-discard-path --enable-magic-quotes --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-fastcgi --enable-fpm --enable-force-cgi-redirect --enable-mbstring --with-mcrypt --enable-ftp --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --with-mime-magic fi if cat /etc/issue | grep -Eqi '(Debian|Ubuntu)';then cd ext/openssl/ wget -c http://soft.vpser.net/lnmp/ext/debian_patches_disable_SSLv2_for_openssl_1_0_0.patch patch -p3 >/usr/local/php/etc/php.ini</usr/local/php/etc/php-fpm.conf<>/etc/rc.local #echo "/etc/init.d/php-fpm start" >>/etc/rc.local chkconfig --level 345 php-fpm on chkconfig --level 345 nginx on fi echo "Starting Nginx..." /etc/init.d/nginx start if [ "$ismysql" = "no" ]; then echo "Starting MariaDB..." /etc/init.d/mariadb start else echo "Starting MySQL..." /etc/init.d/mysql start fi echo "Starting PHP-FPM..." /etc/init.d/php-fpm start if [ -s /etc/init.d/memceached ]; then echo "Starting Memcached..." /etc/init.d/memcacehd start fi fi cd $cur_dir echo "=========================================================================" echo "You have successfully upgrade from $old_php_version to $php_version" echo "=========================================================================" echo "LNMP is tool to auto-compile & install Nginx+MySQL+PHP on Linux " echo "=========================================================================" echo "" echo "For more information please visit http://www.lnmp.org/" echo "" echo "=========================================================================" fi