Advertisement
lastguru

ntphp-custom

May 19th, 2015
330
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 5.87 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. ##########################################################################
  4. # ntPHPselector version: 2.5.1
  5. # Url : https://www.nixtree.com/ntphp.php
  6. # Email : support@nixtree.com
  7. ##########################################################################
  8. # Heavy modifications (reductions) to remove any functionality
  9. # outside of simple downloading and compiling new PHP versions,
  10. # so that the scripts could be used in fastcgi environment
  11. # instead of suphp. Note that no user interface is provided, so
  12. # some other selection must be used
  13. # (e.g. /usr/local/cpanel/cgi-sys/php5)
  14. #
  15. # Modified by : lastguru@gmail.com
  16. ##########################################################################
  17.  
  18. if [ -z $1 ]; then
  19.         echo "Valid options are install, recompile and uninstall"
  20.     echo "Exiting installation"
  21.     exit
  22. fi
  23.  
  24. NATIVE=`php -v | head -1 | awk -F" " {'print $2'}| awk -F"." {'print $2'}`
  25. echo "5.3" >> /tmp/phpver.txt
  26. echo "5.4" >> /tmp/phpver.txt
  27. echo "5.5" >> /tmp/phpver.txt
  28. cat /tmp/phpver.txt | grep -v 5.$NATIVE > /tmp/phpver1.txt
  29. ADD1=`head -1 /tmp/phpver1.txt| awk -F"." {'print $2'}`
  30. ADD2=`head -2 /tmp/phpver1.txt| tail -1| awk -F"." {'print $2'}`
  31. SUPHPCONFIG='/opt/suphp/etc/suphp.conf'
  32.  
  33. ########Functions Start Here###########
  34. clean_install() {
  35.     rm -f /tmp/phpver.txt
  36.     rm -f /tmp/phpver1.txt
  37.     rm -f /tmp/phpverinst.txt
  38.     rm -rf /usr/local/src/ntphpselector
  39.     rm -f /tmp/phpconf.txt
  40. }
  41.  
  42. phpinstall() {
  43.  
  44.     MAJVER=`echo $1 | awk -F"_" {'print $1'}`
  45.     php-cli  -i |grep configure|sed 's/Configure Command =>  //g' | sed "s/'//g" > /tmp/phpconf.txt
  46.     sed -i -e "s/prefix=\/usr\/local/prefix=\/opt\/ntphp\/php5$MAJVER/g" -e 's/.\/configure//g' -e 's/--with-apxs2=\/usr\/local\/apache\/bin\/apxs//g' -e 's/--with-config-file-path=\/usr\/local\/lib//g' -e 's/--with-config-file-scan-dir=\/usr\/local\/lib\/php.ini.d//g'  /tmp/phpconf.txt
  47.     if grep enable-pdo /tmp/phpconf.txt >> /dev/null; then
  48.         yum -yv install sqlite-devel
  49.                 if [ $MAJVER -eq 3 ] || [ $MAJVER -eq 2 ]; then
  50.                         sed -i -e "s/$/ --with-sqlite=shared/g" -e "s/$/ --with-sqlite3=shared/g"  /tmp/phpconf.txt
  51.                 fi
  52.  
  53.     fi
  54.     cd /usr/local/src/ntphpselector
  55.     wget --no-check-certificate http://httpupdate.cpanel.net/cpanelsync/easy/targz/Cpanel/Easy/PHP5/$1.pm.tar.gz.bz2
  56.     bunzip2 $1.pm.tar.gz.bz2
  57.     tar -xvzf $1.pm.tar.gz
  58.     cd php-*
  59.     wget --no-check-certificate https://www.nixtree.com/download/free/ntphp/sqlite.patch
  60.     /usr/bin/patch -p1 < ./sqlite.patch
  61.     ./configure `cat /tmp/phpconf.txt` && make && make install
  62.     if [ ! -d /opt/ntphp/php5$MAJVER ]; then
  63.         echo "COMPILE ERROR FOR 5$MAJVER"
  64.         echo "Exiting Installation"
  65.         clean_install
  66.         echo " Please open a new thread at http://forum.nixtree.com/ if you meet with any issues"
  67.         exit
  68.    
  69.     else
  70.         echo "SUCCESSFULLY COMPILED 5$MAJVER"
  71.     fi
  72.     sleep 5
  73.     if [ ! -f  /opt/ntphp/php5$MAJVER/lib/php.ini ]; then
  74.      /bin/cp -rf php.ini-production /opt/ntphp/php5$MAJVER/lib/php.ini
  75.     fi
  76.     if grep enable-pdo /tmp/phpconf.txt >> /dev/null; then
  77.         if ! grep pdo.so /opt/ntphp/php5$MAJVER/lib/php.ini >> /dev/null; then
  78.                 if [ $MAJVER -eq 4 ] || [ $MAJVER -eq 5 ];  then
  79.                         echo "extension=pdo.so" >> /opt/ntphp/php5$MAJVER/lib/php.ini
  80.                         echo "extension=pdo_mysql.so" >> /opt/ntphp/php5$MAJVER/lib/php.ini
  81.                 else
  82.                         echo "extension=pdo.so" >> /opt/ntphp/php5$MAJVER/lib/php.ini
  83.                         echo "extension=pdo_mysql.so" >> /opt/ntphp/php5$MAJVER/lib/php.ini
  84.                         echo "extension=pdo_sqlite.so" >> /opt/ntphp/php5$MAJVER/lib/php.ini
  85.                 fi
  86.         fi
  87.     fi
  88.  
  89.     TZONE=`cat /etc/sysconfig/clock | grep ZONE | sed -e "s/ZONE=//g" | sed -e 's/\//\\\\\//g'`
  90.     echo "System timezone: $TZONE set to date.timezone param in php.ini"
  91.     sed -i -e "s/;date.timezone =/date.timezone=$TZONE/g" /opt/ntphp/php5$MAJVER/lib/php.ini
  92.     sed -i -e "s/short_open_tag = Off/short_open_tag = On/g" /opt/ntphp/php5$MAJVER/lib/php.ini
  93.  
  94.     cd /usr/local/src/ntphpselector
  95.     rm -rf php-*
  96.     rm -rf $1.pm.tar.gz
  97.  
  98. }
  99.  
  100. ########Main############################
  101. echo "Cleaning left-over files if you have attempted to run this script previously"
  102. clean_install
  103. sleep 1
  104.  
  105. rm -f /tmp/phpver1.txt
  106. wget --no-check-certificate --directory-prefix=/tmp https://www.nixtree.com/download/free/phpver1.txt
  107. cat /tmp/phpver1.txt |  grep -v $NATIVE"_" | grep -v "2_" > /tmp/phpverinst.txt
  108.  
  109. if [ $1 == "install" ]; then
  110.     if [ -d /opt/ntphp ]; then
  111.         echo "ntPHPSelector installation detected. Please uninstall and then install"
  112.         exit
  113.     fi
  114.     echo "You have PHP 5.$NATIVE is installed on the server. This script will install 5.$ADD1 and 5.$ADD2"
  115.     sleep 2
  116.  
  117.     mkdir /usr/local/src/ntphpselector
  118.     mkdir /opt/ntphp
  119.     for ver in `cat /tmp/phpverinst.txt`; do
  120.         phpinstall $ver
  121.     done
  122.     clean_install
  123. elif [ $1 == "recompile" ]; then
  124.     if [ -z $2 ]; then
  125.         echo "Possible compile options are 4 and 5"
  126.         exit
  127.     fi
  128.     if [ $2 -eq $NATIVE ]; then
  129.             echo  "To recompile PHP installed via cPanel, use EasyApache"
  130.             clean_install
  131.             exit
  132.     fi
  133.     if  [ $2 -eq 2 ] || [ $2 -eq 3 ] || [ $2 -eq 4 ] || [ $2 -eq 5 ]; then
  134.         mkdir /usr/local/src/ntphpselector
  135.         mkdir /opt/ntphp
  136.         phpinstall `grep  $2_  /tmp/phpverinst.txt`
  137.         clean_install
  138.     elif [ $2 == "00" ]; then
  139.     echo "You have PHP 5.$NATIVE is installed on the server. This script will install 5.$ADD1 and 5.$ADD2"
  140.     sleep 2
  141.             mkdir /usr/local/src/ntphpselector
  142.             mkdir /opt/ntphp
  143.             for ver in `cat /tmp/phpverinst.txt`; do
  144.                     phpinstall $ver
  145.             done
  146.     else
  147.         echo "Wrong compile option given"
  148.         exit
  149.     fi
  150.     clean_install
  151. elif [ $1 == "uninstall" ]; then
  152.     clean_install
  153.     rm -rf /opt/ntphp
  154.     clean_install
  155.     echo "Uninstallation Completed....."
  156.     echo "Thank you for using ntPHPSelector"
  157. else
  158.         echo "Wrong choice"
  159.     exit
  160. fi
  161. rm -f /usr/local/src/ntphpselector*
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement