#!/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 ' 33[1;31m当前目录没有找到相应的安装包,请提前准备好相关包! 33[0m'; exit 1; }
# 安装相关依赖包
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 " 33[1;31m${Version}安装成功! 33[0m"