php-5.3.sh 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. #!/bin/bash
  2. # Author: yeho <lj2007331 AT gmail.com>
  3. # Blog: http://blog.linuxeye.com
  4. Install_PHP-5-3()
  5. {
  6. cd $oneinstack_dir/src
  7. . ../functions/download.sh
  8. . ../functions/check_os.sh
  9. . ../options.conf
  10. src_url=http://ftp.gnu.org/pub/gnu/libiconv/libiconv-$libiconv_version.tar.gz && Download_src
  11. src_url=http://downloads.sourceforge.net/project/mcrypt/Libmcrypt/$libmcrypt_version/libmcrypt-$libmcrypt_version.tar.gz && Download_src
  12. src_url=http://downloads.sourceforge.net/project/mhash/mhash/$mhash_version/mhash-$mhash_version.tar.gz && Download_src
  13. src_url=http://downloads.sourceforge.net/project/mcrypt/MCrypt/$mcrypt_version/mcrypt-$mcrypt_version.tar.gz && Download_src
  14. src_url=http://www.php.net/distributions/php-$php_3_version.tar.gz && Download_src
  15. src_url=http://mirrors.linuxeye.com/lnmp/src/php5.3patch && Download_src
  16. tar xzf libiconv-$libiconv_version.tar.gz
  17. cd libiconv-$libiconv_version
  18. ./configure --prefix=/usr/local
  19. [ -n "`cat /etc/issue | grep 'Ubuntu 13'`" ] && sed -i 's@_GL_WARN_ON_USE (gets@//_GL_WARN_ON_USE (gets@' srclib/stdio.h
  20. [ -n "`cat /etc/issue | grep 'Ubuntu 14'`" ] && sed -i 's@gets is a security@@' srclib/stdio.h
  21. make && make install
  22. cd ../
  23. /bin/rm -rf libiconv-$libiconv_version
  24. tar xzf libmcrypt-$libmcrypt_version.tar.gz
  25. cd libmcrypt-$libmcrypt_version
  26. ./configure
  27. make && make install
  28. ldconfig
  29. cd libltdl/
  30. ./configure --enable-ltdl-install
  31. make && make install
  32. cd ../../
  33. /bin/rm -rf libmcrypt-$libmcrypt_version
  34. tar xzf mhash-$mhash_version.tar.gz
  35. cd mhash-$mhash_version
  36. ./configure
  37. make && make install
  38. cd ../
  39. /bin/rm -rf mhash-$mhash_version
  40. echo '/usr/local/lib' > /etc/ld.so.conf.d/local.conf
  41. ldconfig
  42. OS_CentOS='ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config \n
  43. if [ `getconf WORD_BIT` == 32 ] && [ `getconf LONG_BIT` == 64 ];then \n
  44. ln -s /lib64/libpcre.so.0.0.1 /lib64/libpcre.so.1 \n
  45. else \n
  46. ln -s /lib/libpcre.so.0.0.1 /lib/libpcre.so.1 \n
  47. fi'
  48. OS_command
  49. tar xzf mcrypt-$mcrypt_version.tar.gz
  50. cd mcrypt-$mcrypt_version
  51. ldconfig
  52. ./configure
  53. make && make install
  54. cd ../
  55. /bin/rm -rf mcrypt-$mcrypt_version
  56. tar xzf php-$php_3_version.tar.gz
  57. id -u $run_user >/dev/null 2>&1
  58. [ $? -ne 0 ] && useradd -M -s /sbin/nologin $run_user
  59. [ ! -e "fpm-race-condition.patch" ] && wget -O fpm-race-condition.patch 'https://bugs.php.net/patch-display.php?bug_id=65398&patch=fpm-race-condition.patch&revision=1375772074&download=1'
  60. patch -d php-$php_3_version -p0 < fpm-race-condition.patch
  61. cd php-$php_3_version
  62. patch -p1 < ../php5.3patch
  63. make clean
  64. [ ! -d "$php_install_dir" ] && mkdir -p $php_install_dir
  65. if [ "$Apache_version" == '1' -o "$Apache_version" == '2' ];then
  66. CFLAGS= CXXFLAGS= ./configure --prefix=$php_install_dir --with-config-file-path=$php_install_dir/etc \
  67. --with-apxs2=$apache_install_dir/bin/apxs --disable-fileinfo \
  68. --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd \
  69. --with-iconv-dir=/usr/local --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib \
  70. --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-exif \
  71. --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex \
  72. --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl \
  73. --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-ftp \
  74. --with-gettext --enable-zip --enable-soap --disable-ipv6 --disable-debug
  75. else
  76. CFLAGS= CXXFLAGS= ./configure --prefix=$php_install_dir --with-config-file-path=$php_install_dir/etc \
  77. --with-fpm-user=$run_user --with-fpm-group=$run_user --enable-fpm --disable-fileinfo \
  78. --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd \
  79. --with-iconv-dir=/usr/local --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib \
  80. --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-exif \
  81. --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex \
  82. --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl \
  83. --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-ftp \
  84. --with-gettext --enable-zip --enable-soap --disable-ipv6 --disable-debug
  85. fi
  86. make ZEND_EXTRA_LIBS='-liconv'
  87. make install
  88. if [ -d "$php_install_dir/bin" ];then
  89. echo -e "\033[32mPHP install successfully! \033[0m"
  90. else
  91. rm -rf $php_install_dir
  92. echo -e "\033[31mPHP install failed, Please Contact the author! \033[0m"
  93. kill -9 $$
  94. fi
  95. [ -z "`grep ^'export PATH=' /etc/profile`" ] && echo "export PATH=$php_install_dir/bin:\$PATH" >> /etc/profile
  96. [ -n "`grep ^'export PATH=' /etc/profile`" -a -z "`grep $php_install_dir /etc/profile`" ] && sed -i "s@^export PATH=\(.*\)@export PATH=$php_install_dir/bin:\1@" /etc/profile
  97. . /etc/profile
  98. # wget -c http://pear.php.net/go-pear.phar
  99. # $php_install_dir/bin/php go-pear.phar
  100. /bin/cp php.ini-production $php_install_dir/etc/php.ini
  101. # Modify php.ini
  102. Mem=`free -m | awk '/Mem:/{print $2}'`
  103. if [ $Mem -gt 1024 -a $Mem -le 1500 ];then
  104. Memory_limit=192
  105. elif [ $Mem -gt 1500 -a $Mem -le 3500 ];then
  106. Memory_limit=256
  107. elif [ $Mem -gt 3500 -a $Mem -le 4500 ];then
  108. Memory_limit=320
  109. elif [ $Mem -gt 4500 ];then
  110. Memory_limit=448
  111. else
  112. Memory_limit=128
  113. fi
  114. sed -i "s@^memory_limit.*@memory_limit = ${Memory_limit}M@" $php_install_dir/etc/php.ini
  115. sed -i 's@^output_buffering =@output_buffering = On\noutput_buffering =@' $php_install_dir/etc/php.ini
  116. sed -i 's@^;cgi.fix_pathinfo.*@cgi.fix_pathinfo=0@' $php_install_dir/etc/php.ini
  117. sed -i 's@^short_open_tag = Off@short_open_tag = On@' $php_install_dir/etc/php.ini
  118. sed -i 's@^expose_php = On@expose_php = Off@' $php_install_dir/etc/php.ini
  119. sed -i 's@^request_order.*@request_order = "CGP"@' $php_install_dir/etc/php.ini
  120. sed -i 's@^;date.timezone.*@date.timezone = Asia/Shanghai@' $php_install_dir/etc/php.ini
  121. sed -i 's@^post_max_size.*@post_max_size = 50M@' $php_install_dir/etc/php.ini
  122. sed -i 's@^upload_max_filesize.*@upload_max_filesize = 50M@' $php_install_dir/etc/php.ini
  123. sed -i 's@^;upload_tmp_dir.*@upload_tmp_dir = /tmp@' $php_install_dir/etc/php.ini
  124. sed -i 's@^max_execution_time.*@max_execution_time = 5@' $php_install_dir/etc/php.ini
  125. sed -i 's@^disable_functions.*@disable_functions = passthru,exec,system,chroot,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,fsocket,popen@' $php_install_dir/etc/php.ini
  126. sed -i 's@^session.cookie_httponly.*@session.cookie_httponly = 1@' $php_install_dir/etc/php.ini
  127. sed -i 's@^mysqlnd.collect_memory_statistics.*@mysqlnd.collect_memory_statistics = On@' $php_install_dir/etc/php.ini
  128. [ -e /usr/sbin/sendmail ] && sed -i 's@^;sendmail_path.*@sendmail_path = /usr/sbin/sendmail -t -i@' $php_install_dir/etc/php.ini
  129. if [ "$Apache_version" != '1' -a "$Apache_version" != '2' ];then
  130. # php-fpm Init Script
  131. /bin/cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
  132. chmod +x /etc/init.d/php-fpm
  133. OS_CentOS='chkconfig --add php-fpm \n
  134. chkconfig php-fpm on'
  135. OS_Debian_Ubuntu='update-rc.d php-fpm defaults'
  136. OS_command
  137. cat > $php_install_dir/etc/php-fpm.conf <<EOF
  138. ;;;;;;;;;;;;;;;;;;;;;
  139. ; FPM Configuration ;
  140. ;;;;;;;;;;;;;;;;;;;;;
  141. ;;;;;;;;;;;;;;;;;;
  142. ; Global Options ;
  143. ;;;;;;;;;;;;;;;;;;
  144. [global]
  145. pid = run/php-fpm.pid
  146. error_log = log/php-fpm.log
  147. log_level = warning
  148. emergency_restart_threshold = 30
  149. emergency_restart_interval = 60s
  150. process_control_timeout = 5s
  151. daemonize = yes
  152. ;;;;;;;;;;;;;;;;;;;;
  153. ; Pool Definitions ;
  154. ;;;;;;;;;;;;;;;;;;;;
  155. [$run_user]
  156. listen = /dev/shm/php-cgi.sock
  157. listen.backlog = -1
  158. listen.allowed_clients = 127.0.0.1
  159. listen.owner = $run_user
  160. listen.group = $run_user
  161. listen.mode = 0666
  162. user = $run_user
  163. group = $run_user
  164. pm = dynamic
  165. pm.max_children = 12
  166. pm.start_servers = 8
  167. pm.min_spare_servers = 6
  168. pm.max_spare_servers = 12
  169. pm.max_requests = 2048
  170. pm.process_idle_timeout = 10s
  171. request_terminate_timeout = 120
  172. request_slowlog_timeout = 0
  173. slowlog = log/slow.log
  174. rlimit_files = 51200
  175. rlimit_core = 0
  176. catch_workers_output = yes
  177. ;env[HOSTNAME] = $HOSTNAME
  178. env[PATH] = /usr/local/bin:/usr/bin:/bin
  179. env[TMP] = /tmp
  180. env[TMPDIR] = /tmp
  181. env[TEMP] = /tmp
  182. EOF
  183. [ -d "/run/shm" -a ! -e "/dev/shm" ] && sed -i 's@/dev/shm@/run/shm@' $php_install_dir/etc/php-fpm.conf $oneinstack_dir/vhost.sh $oneinstack_dir/conf/nginx.conf
  184. if [ $Mem -le 3000 ];then
  185. sed -i "s@^pm.max_children.*@pm.max_children = $(($Mem/2/20))@" $php_install_dir/etc/php-fpm.conf
  186. sed -i "s@^pm.start_servers.*@pm.start_servers = $(($Mem/2/30))@" $php_install_dir/etc/php-fpm.conf
  187. sed -i "s@^pm.min_spare_servers.*@pm.min_spare_servers = $(($Mem/2/40))@" $php_install_dir/etc/php-fpm.conf
  188. sed -i "s@^pm.max_spare_servers.*@pm.max_spare_servers = $(($Mem/2/20))@" $php_install_dir/etc/php-fpm.conf
  189. elif [ $Mem -gt 3000 -a $Mem -le 4500 ];then
  190. sed -i "s@^pm.max_children.*@pm.max_children = 80@" $php_install_dir/etc/php-fpm.conf
  191. sed -i "s@^pm.start_servers.*@pm.start_servers = 50@" $php_install_dir/etc/php-fpm.conf
  192. sed -i "s@^pm.min_spare_servers.*@pm.min_spare_servers = 40@" $php_install_dir/etc/php-fpm.conf
  193. sed -i "s@^pm.max_spare_servers.*@pm.max_spare_servers = 80@" $php_install_dir/etc/php-fpm.conf
  194. elif [ $Mem -gt 4500 -a $Mem -le 6500 ];then
  195. sed -i "s@^pm.max_children.*@pm.max_children = 90@" $php_install_dir/etc/php-fpm.conf
  196. sed -i "s@^pm.start_servers.*@pm.start_servers = 60@" $php_install_dir/etc/php-fpm.conf
  197. sed -i "s@^pm.min_spare_servers.*@pm.min_spare_servers = 50@" $php_install_dir/etc/php-fpm.conf
  198. sed -i "s@^pm.max_spare_servers.*@pm.max_spare_servers = 90@" $php_install_dir/etc/php-fpm.conf
  199. elif [ $Mem -gt 6500 -a $Mem -le 8500 ];then
  200. sed -i "s@^pm.max_children.*@pm.max_children = 100@" $php_install_dir/etc/php-fpm.conf
  201. sed -i "s@^pm.start_servers.*@pm.start_servers = 70@" $php_install_dir/etc/php-fpm.conf
  202. sed -i "s@^pm.min_spare_servers.*@pm.min_spare_servers = 60@" $php_install_dir/etc/php-fpm.conf
  203. sed -i "s@^pm.max_spare_servers.*@pm.max_spare_servers = 100@" $php_install_dir/etc/php-fpm.conf
  204. elif [ $Mem -gt 8500 ];then
  205. sed -i "s@^pm.max_children.*@pm.max_children = 120@" $php_install_dir/etc/php-fpm.conf
  206. sed -i "s@^pm.start_servers.*@pm.start_servers = 80@" $php_install_dir/etc/php-fpm.conf
  207. sed -i "s@^pm.min_spare_servers.*@pm.min_spare_servers = 70@" $php_install_dir/etc/php-fpm.conf
  208. sed -i "s@^pm.max_spare_servers.*@pm.max_spare_servers = 120@" $php_install_dir/etc/php-fpm.conf
  209. fi
  210. #[ "$Web_yn" == 'n' ] && sed -i "s@^listen =.*@listen = $local_IP:9000@" $php_install_dir/etc/php-fpm.conf
  211. service php-fpm start
  212. elif [ "$Apache_version" == '1' -o "$Apache_version" == '2' ];then
  213. service httpd restart
  214. fi
  215. cd ..
  216. [ -d "$php_install_dir" ] && /bin/rm -rf php-$php_3_version
  217. cd ..
  218. }