php-8.4.sh 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. #!/bin/bash
  2. Install_PHP84() {
  3. # Check CentOS version
  4. if [ -f /etc/redhat-release ]; then
  5. OS_VERSION=$(grep -oE '[0-9]+\.[0-9]+' /etc/redhat-release | cut -d'.' -f1)
  6. if [ "${OS_VERSION}" -lt "8" ]; then
  7. echo "${CFAILURE}Error: PHP 8.4 cannot be installed on CentOS ${OS_VERSION}. Minimum required version is CentOS 8.${CEND}"
  8. kill -9 $$; exit 1;
  9. fi
  10. fi
  11. pushd ${oneinstack_dir}/src > /dev/null
  12. if [ ! -e "${php_install_dir}/bin/phpize" ]; then
  13. PHP_version=8.4.4
  14. PHP_main_ver=84
  15. # 下载和校验
  16. src_url=https://www.php.net/distributions/php-${PHP_version}.tar.gz && Download_src
  17. # 编译安装
  18. tar xzf php-${PHP_version}.tar.gz
  19. pushd php-${PHP_version} > /dev/null
  20. make clean
  21. [ ! -d "${php_install_dir}" ] && mkdir -p ${php_install_dir}
  22. # PHP 8.4 特定的编译选项
  23. ./configure --prefix=${php_install_dir} \
  24. --with-config-file-path=${php_install_dir}/etc \
  25. --with-config-file-scan-dir=${php_install_dir}/etc/php.d \
  26. --with-fpm-user=${run_user} \
  27. --with-fpm-group=${run_user} \
  28. --enable-mysqlnd \
  29. --with-mysqli=mysqlnd \
  30. --with-pdo-mysql=mysqlnd \
  31. --with-sqlite3 \
  32. --with-pdo-sqlite \
  33. --with-openssl \
  34. --with-zlib \
  35. --with-zip \
  36. --with-curl \
  37. --with-iconv \
  38. --with-gettext \
  39. --with-readline \
  40. --with-ldapsasl \
  41. --with-sodium \
  42. --enable-bcmath \
  43. --enable-fpm \
  44. --enable-xml \
  45. --enable-sysvsem \
  46. --enable-sysvshm \
  47. --enable-sysvmsg \
  48. --enable-shmop \
  49. --enable-sockets \
  50. --enable-mbstring \
  51. --enable-pcntl \
  52. --enable-soap \
  53. --enable-gd \
  54. --enable-intl \
  55. --enable-opcache \
  56. --enable-ftp \
  57. --enable-exif \
  58. --enable-calendar \
  59. --without-pear \
  60. --disable-phar \
  61. --disable-rpath
  62. make -j ${THREAD} && make install
  63. if [ -e "${php_install_dir}/bin/phpize" ]; then
  64. # php.ini配置
  65. mkdir -p ${php_install_dir}/etc/php.d
  66. \cp php.ini-production ${php_install_dir}/etc/php.ini
  67. tee -a ${php_install_dir}/etc/php.ini <<EOF
  68. ; Modify php.ini Config by User
  69. memory_limit = 512M
  70. output_buffering = On
  71. short_open_tag = On
  72. expose_php = Off
  73. request_order = "CGP"
  74. date.timezone = ${timezone}
  75. post_max_size = 128M
  76. upload_max_filesize = 128M
  77. max_execution_time = 300
  78. realpath_cache_size = 2M
  79. disable_functions = passthru,exec,system,chroot,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_restore,dl,readlink,symlink,popepassthru,stream_socket_server,fsocket,popen
  80. max_file_uploads = 20
  81. max_input_time = 300
  82. EOF
  83. if [ -e /usr/sbin/sendmail ]; then
  84. tee -a ${php_install_dir}/etc/php.ini <<EOF
  85. sendmail_path = /usr/sbin/sendmail -t -i
  86. EOF
  87. fi
  88. # php-fpm.conf配置
  89. \cp sapi/fpm/php-fpm.conf.in ${php_install_dir}/etc/php-fpm.conf
  90. \cp sapi/fpm/www.conf.in ${php_install_dir}/etc/php-fpm.d/www.conf
  91. sed -i "s@^include=@;include=@" ${php_install_dir}/etc/php-fpm.conf
  92. tee -a ${php_install_dir}/etc/php-fpm.conf <<EOF
  93. ; Modify php-fpm.conf Config by User
  94. pid = run/php-fpm.pid
  95. error_log = log/php-fpm.log
  96. log_level = warning
  97. emergency_restart_threshold = 30
  98. emergency_restart_interval = 60s
  99. process_control_timeout = 5s
  100. daemonize = yes
  101. include=${php_install_dir}/etc/php-fpm.d/*.conf
  102. EOF
  103. # php-fpm.d/www.conf配置
  104. tee -a ${php_install_dir}/etc/php-fpm.d/www.conf <<EOF
  105. ; Modify php-fpm.d/www.conf Config by User
  106. [${run_user}]
  107. listen = /dev/shm/php-cgi.sock
  108. listen.backlog = 65535
  109. listen.allowed_clients = 127.0.0.1
  110. listen.owner = ${run_user}
  111. listen.group = ${run_group}
  112. listen.mode = 0666
  113. user = ${run_user}
  114. group = ${run_group}
  115. pm = dynamic
  116. pm.max_children = 20
  117. pm.start_servers = 15
  118. pm.min_spare_servers = 10
  119. pm.max_spare_servers = 20
  120. pm.max_requests = 10240
  121. pm.process_idle_timeout = 10s
  122. pm.status_path = /php-fpm_status
  123. request_terminate_timeout = 300
  124. request_slowlog_timeout = 10s
  125. slowlog = var/log/slow.log
  126. rlimit_files = 65535
  127. rlimit_core = 0
  128. catch_workers_output = yes
  129. php_admin_value[error_log] = var/log/php-fpm.error.log
  130. php_admin_flag[log_errors] = on
  131. php_admin_value[opcache.enable] = 1
  132. php_admin_value[opcache.memory_consumption] = 128
  133. php_admin_value[opcache.interned_strings_buffer] = 16
  134. php_admin_value[opcache.max_accelerated_files] = 10000
  135. php_admin_value[opcache.validate_timestamps] = 1
  136. php_admin_value[opcache.revalidate_freq] = 60
  137. env[HOSTNAME] = $HOSTNAME
  138. env[PATH] = /usr/local/bin:/usr/bin:/bin
  139. env[TMP] = /tmp
  140. env[TMPDIR] = /tmp
  141. env[TEMP] = /tmp
  142. ; Recommended, if you need to adjust, please modify the following parameters.
  143. EOF
  144. # php-fpm内存优化
  145. if [ $Mem -gt 8500 ]; then
  146. tee -a ${php_install_dir}/etc/php-fpm.d/www.conf <<EOF
  147. pm.max_children = 80
  148. pm.start_servers = 60
  149. pm.min_spare_servers = 50
  150. pm.max_spare_servers = 80
  151. EOF
  152. elif [ $Mem -gt 6500 ]; then
  153. tee -a ${php_install_dir}/etc/php-fpm.d/www.conf <<EOF
  154. pm.max_children = 70
  155. pm.start_servers = 50
  156. pm.min_spare_servers = 40
  157. pm.max_spare_servers = 70
  158. EOF
  159. elif [ $Mem -gt 4500 ]; then
  160. tee -a ${php_install_dir}/etc/php-fpm.d/www.conf <<EOF
  161. pm.max_children = 60
  162. pm.start_servers = 40
  163. pm.min_spare_servers = 30
  164. pm.max_spare_servers = 60
  165. EOF
  166. elif [ $Mem -gt 3000 ]; then
  167. tee -a ${php_install_dir}/etc/php-fpm.d/www.conf <<EOF
  168. pm.max_children = 50
  169. pm.start_servers = 30
  170. pm.min_spare_servers = 20
  171. pm.max_spare_servers = 50
  172. EOF
  173. else
  174. tee -a ${php_install_dir}/etc/php-fpm.d/www.conf <<EOF
  175. pm.max_children = $(($Mem/3/20))
  176. pm.start_servers = $(($Mem/3/30))
  177. pm.min_spare_servers = $(($Mem/3/40))
  178. pm.max_spare_servers = $(($Mem/3/20))
  179. EOF
  180. fi
  181. # 启动脚本
  182. \cp ${oneinstack_dir}/init.d/php-fpm.service /lib/systemd/system/
  183. sed -i "s@/usr/local/php@${php_install_dir}@g" /lib/systemd/system/php-fpm.service
  184. systemctl enable --now php-fpm.service
  185. # 检测php-fpm是否启动成功,没有成功则重启php-fpm再试一次,如果还不成功则退出
  186. systemctl status php-fpm.service | grep "Active: active (running)"
  187. if [ $? -ne 0 ]; then
  188. systemctl restart php-fpm.service
  189. systemctl status php-fpm.service | grep "Active: active (running)"
  190. if [ $? -ne 0 ]; then
  191. echo "${CFAILURE}PHP ${PHP_version} install failed, Please Contact the author! ${CEND}"
  192. kill -9 $$; exit 1;
  193. fi
  194. fi
  195. # 环境变量
  196. echo "export PATH=${php_install_dir}/bin:\$PATH" > /etc/profile.d/php.sh
  197. echo "${CSUCCESS}PHP ${PHP_version} installed successfully! ${CEND}"
  198. rm -rf php-${PHP_version}
  199. else
  200. rm -rf ${php_install_dir}
  201. echo "${CFAILURE}PHP ${PHP_version} install failed, Please Contact the author! ${CEND}"
  202. kill -9 $$; exit 1;
  203. fi
  204. popd > /dev/null
  205. fi
  206. popd > /dev/null
  207. }