Linux环境安装PHP自动化脚本

小柒博客 评论67,649字数 493阅读1分38秒阅读模式

此脚本是PHP安装脚本,有需要朋友可以参考,脚本内容如下:

系统环境:CentOS 7.9

软件版本:7.3.7

[root@localhost ~]# vim auto_install_php.sh

  1. #!/bin/bash
  2. #2020-3-12 14:35:50
  3. #By Author YangXingZhen
  4. #Auto Install PHP Server
  5. source /etc/rc.d/init.d/functions
  6. #Define PHP path variables
  7. PHP_URL=http://mirrors.sohu.com/php
  8. PHP_FILE=php-7.3.7.tar.gz
  9. PHP_FILE_DIR=php-7.3.7
  10. PHP_PREFIX=/usr/local/php
  11. USER=www
  12. #Define ZIP path variables
  13. ZIP_URL=https://nih.at/libzip
  14. ZIP_FILE=libzip-1.2.0.tar.gz
  15. ZIP_FILE_DIR=libzip-1.2.0
  16. function install_libzip (){
  17. yum y install wget gcc gcc-c++
  18. wget -c ${ZIP_URL}/${ZIP_FILE}
  19. tar zxf ${ZIP_FILE}
  20. cd ${ZIP_FILE_DIR}
  21. ./configure
  22. if [ $? -eq 0 ];then
  23. make && make install
  24. action "The Libzip Install Sussess..." /bin/true
  25. else
  26. action "The Libzip Install Failed..." /bin/false
  27. exit 1
  28. fi
  29. cat >/etc/ld.so.conf <<EOF
  30. /usr/local/lib64
  31. /usr/local/lib
  32. /usr/lib
  33. /usr/lib64
  34. EOF
  35. ldconfig -v
  36. }
  37. function install_php {
  38. if [ ! -d ${PHP_PREFIX} ];then
  39. #Install Package
  40. yum -y install epel-release
  41. yum -y install wget gcc gcc-c++ pcre pcre-devel openssl openssl-devellibxml2 libxml2-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel cmake
  42. cd ~ && wget -c ${PHP_URL}/${PHP_FILE}
  43. tar zxf ${PHP_FILE}
  44. cd ${PHP_FILE_DIR}
  45. ./configure --prefix=${PHP_PREFIX} \
  46. --with-config-file-path=/etc \
  47. --enable-fpm \
  48. --with-fpm-user=${USER} \
  49. --with-fpm-group=${USER} \
  50. --enable-inline-optimization \
  51. --disable-debug \
  52. --disable-rpath \
  53. --enable-shared \
  54. --enable-soap \
  55. --with-libxml-dir \
  56. --with-xmlrpc \
  57. --with-openssl \
  58. --with-mhash \
  59. --with-pcre-regex \
  60. --with-sqlite3 \
  61. --with-zlib \
  62. --enable-bcmath \
  63. --with-iconv \
  64. --with-bz2 \
  65. --enable-calendar \
  66. --with-curl \
  67. --with-cdb \
  68. --enable-dom \
  69. --enable-exif \
  70. --enable-fileinfo \
  71. --enable-filter \
  72. --with-pcre-dir \
  73. --enable-ftp \
  74. --with-gd \
  75. --with-openssl-dir \
  76. --with-jpeg-dir \
  77. --with-png-dir \
  78. --with-zlib-dir \
  79. --with-freetype-dir \
  80. --with-gettext \
  81. --with-gmp \
  82. --with-mhash \
  83. --enable-json \
  84. --enable-mbstring \
  85. --enable-mbregex \
  86. --enable-mbregex-backtrack \
  87. --with-onig \
  88. --enable-pdo \
  89. --with-mysqli=mysqlnd \
  90. --with-pdo-mysql=mysqlnd \
  91. --with-zlib-dir \
  92. --with-pdo-sqlite \
  93. --with-readline \
  94. --enable-session \
  95. --enable-shmop \
  96. --enable-simplexml \
  97. --enable-sockets \
  98. --enable-sysvmsg \
  99. --enable-sysvsem \
  100. --enable-sysvshm \
  101. --enable-wddx \
  102. --with-libxml-dir \
  103. --with-xsl \
  104. --enable-zip \
  105. --enable-mysqlnd-compression-support \
  106. --with-pear \
  107. --enable-opcache
  108. if [ $? -eq 0 ];then
  109. \cp /usr/local/lib/libzip/include/zipconf.h /usr/local/include/zipconf.h
  110. make && make install
  111. action "The PHP Install Sussess..." /bin/true
  112. else
  113. action "The PHP Install Failed..." /bin/false
  114. exit 1
  115. fi
  116. else
  117. echo -e "\033[31mThe PHP already Install...\033[0m"
  118. exit 1
  119. fi
  120. }
  121. function config_php {
  122. \cp php.ini-production /etc/php.ini
  123. \cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
  124. \cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
  125. \cp sapi/fpm/php-fpm.service /usr/lib/systemd/system
  126. useradd -s /sbin/nologin ${USER} >/dev/null 2>&1
  127. cat >/usr/local/php/etc/php-fpm.d/www.conf <<EOF
  128. [www]
  129. listen = 0.0.0.0:9000
  130. listen.mode = 0666
  131. user = www
  132. group = www
  133. pm = dynamic
  134. pm.max_children = 128
  135. pm.start_servers = 20
  136. pm.min_spare_servers = 5
  137. pm.max_spare_servers = 35
  138. pm.max_requests = 10000
  139. rlimit_files = 1024
  140. slowlog = log/$pool.log.slow
  141. EOF
  142. systemctl enable php-fpm
  143. systemctl start php-fpm
  144. }
  145. function main (){
  146. install_libzip
  147. install_php
  148. config_php
  149. }
  150. main

脚本执行方式:

[root@localhost ~]# sh auto_install_php.sh

若文章图片、下载链接等信息出错,请在评论区留言反馈,博主将第一时间更新!如本文“对您有用”,欢迎随意打赏,谢谢!

继续阅读
Wechat
微信扫一扫,加我!
weinxin
微信号已复制
微信公众号
微信扫一扫,关注我!
weinxin
公众号已复制
Shell最后更新:2024-1-24
小柒博客
  • 本文由 小柒博客 发表于 2020年4月7日 16:31:10
  • 声明:本站所有文章,如无特殊说明或标注,本站文章均为原创。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。转载请务必保留本文链接:https://www.yangxingzhen.com/6684.html
匿名

发表评论

匿名网友
:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

拖动滑块以完成验证
加载中...