php原始碼編譯安裝指令碼
阿新 • • 發佈:2020-12-01
#!/bin/bash # #******************************************************************** #Author: Wuvikr #QQ: 744123155 #Date: 2020-12-01 #FileName php_src_install.sh #URL: http://www.wuvikr.top #Description The test script #Copyright (C): 2020 All rights reserved #******************************************************************** PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin export PATH CPU=`lscpu | sed -rn 's/^CPU\(s\)[^0-9]+([0-9]+)/\1/p'` Tar=php-7.4.12.tar.bz2 Version=${Tar%.tar*} Dir=/apps/php74 install (){ # 檢測安裝包 [ -f $Tar ] && tar xvf $Tar || echo -e '\033[1;31m當前目錄沒有找到相應的安裝包,請提前準備好相關包!\033[0m' # 安裝相關依賴包 yum -y install gcc libxml2-devel bzip2-devel libmcrypt-devel sqlite-devel oniguruma-devel openssl-devel # 切換目錄 cd $Version # 編譯安裝 ./configure \ --prefix=$Dir \ --enable-mysqlnd \ --with-mysqli=mysqlnd \ --with-pdo-mysql=mysqlnd \ --with-openssl \ --with-zlib \ --with-config-file-path=/etc \ --with-config-file-scan-dir=/etc/php.d \ --enable-mbstring \ --enable-xml \ --enable-sockets \ --enable-fpm \ --enable-maintainer-zts \ --disable-fileinfo make -j $CPU && make install } Configuration (){ #準備PATH變數 echo "PATH=$Dir/bin:$PATH" > /etc/profile.d/php.sh #準備php配置檔案和啟動檔案 cp php.ini-production /etc/php.ini cp sapi/fpm/php-fpm.service /usr/lib/systemd/system/ cp $Dir/etc/php-fpm.conf.default $Dir/etc/php-fpm.conf cp $Dir/etc/php-fpm.d/www.conf.default $Dir/etc/php-fpm.d/www.conf # 修改php-fpm配置檔案 ## 修改使用者組 sed -ri 's#^(user.*)nobody#\1nginx#' $Dir/etc/php-fpm.d/www.conf sed -ri 's#^(group.*)nobody#\1nginx#' $Dir/etc/php-fpm.d/www.conf ## 開啟ping和status頁面 sed -ri 's#^;(pm\.status.*)#\1#' $Dir/etc/php-fpm.d/www.conf sed -ri 's#^;(ping\.path.*)#\1#' $Dir/etc/php-fpm.d/www.conf #開啟opcache加速 mkdir /etc/php.d cat > /etc/php.d/opcache.ini <<EOF [opcache] zend_extension=opcache.so opcache.enable=1 EOF # 重新載入並啟動php-fpm systemctl daemon-reload systemctl enable --now php-fpm.service } install Configuration echo -e "\033[1;31m${Version}安裝成功!\033[0m"