PHP源码安装脚本

#!/bin/bash
#Author Mr.Wu
#PHP安装脚本
#WARNING!!!如网速不好,需上传php-8.1.9.tar.gz包
#2023-3-2 22:55:55
########################################
#定义变量
dep_pack="epel-release make apr* php-mcrypt libmcrypt libmcrypt-devel autoconf automake curl curl-devel gcc gcc-c++  openssl* gd kernel keyutils patch perl re2c kernel-headers compat* mpfr cpp glibc libgomp libstdc++-devel keyutils-libs-devel libcom_err-devel libsepol-devel libselinux-devel krb5-devel zlib zlib-devel libXpm* freetype gd libjpeg* libpng*  libtool* libxml2 libxml2-devel patch libcurl-devel bzip2-devel freetype-devel php-xmlreader php-xmlwriter php-session libjpeg-devel sqlite-devel libwebp expat-devel"
dec_pack="--prefix=/usr/local/php8.1.9 --with-config-file-path=/etc --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --enable-gd --with-iconv -enable-gd --with-iconv --with-expat --with-mhash --with-config-file-scan-dir=/usr/local/php8.1.9/etc/ --with-bz2 --with-zlib --with-jpeg --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --enable-mbregex --enable-fpm --enable-mbstring --enable-ftp --with-openssl --enable-pcntl --enable-sockets --with-xmlrpc --with-zip --enable-soap --without-pear --with-gettext --enable-session --with-curl --with-freetype  --enable-bcmath --enable-ctype"
dev_dir="/dev/null"
php_log="$(pwd)/php-install.log"
src_dir="/usr/local/src"
php_tar="$(pwd)/php-8.1.9.tar.gz"
php_dir="/usr/local/php8.1.9"
aaa="/usr/local/php8.1.9/etc/php-fpm.d/www.conf"
messages=("检查PHP安装包是否存在" "下载PHP安装包" "安装依赖包" "安装oniguruma" "解压PHP安装包" "PHP预编译" "PHP编译" "PHP编译安装" "生成配置文件" "PHP启动管理")
colour=(31 34)
result=("失败!!!" "成功!!!")
########################################
#定义函数
delimiter(){        #定义分隔符
    echo -e "\033[32;1m※※※※※※※※※※※※※※※※※※※※※※※※※※\033[0m"
}
echoinfo(){        #定义输入选项
    echo -e "\033[35;1m#$1\033[0m"
}
echoresult(){        #定义输出选项
    echo -e "\033[$1;1m$2$3\033[0m"
}
if_test(){        #if语句判断
    if [ $? -eq 0 ];then
        echoresult ${colour[1]} $1 ${result[1]}
    else
        echoresult ${colour[0]} $1 ${result[0]}
        exit
    fi
}
get_tar(){        #下载PHP安装包
    delimiter | tee -a $php_log
    echoinfo ${messages[1]} | tee -a $php_log
    wget https://www.php.net/distributions/php-8.1.9.tar.gz &> $dev_dir
    sleep 3
    if_test ${messages[1]} | tee -a $php_log
}
check_tar(){        #检查PHP安装包是否存在
    delimiter | tee -a $php_log
    echoinfo ${messages[0]} | tee -a $php_log
    if [ ! -f $php_tar ];then
        echo -e "\033[31;1m#PHP安装包不存在,请下载!!!\033[0m" | tee -a $php_log
        get_tar
    else
        echo -e "\033[34;1m#PHP安装包已经存在,请解压安装!!!\033[0m" | tee -a $php_log
    fi
}
dep_tar(){        #安装依赖包
    delimiter | tee -a $php_log
    echoinfo ${messages[2]} | tee -a $php_log
    yum -y install $dep_pack &> $dev_dir
    sleep 3
    if_test ${messages[2]} | tee -a $php_log
}
ins_onigur(){    #安装oniguruma
    delimiter | tee -a $php_log
    echoinfo ${messages[3]} | tee -a $php_log
    wget https://rpms.remirepo.net/enterprise/7/remi/x86_64/oniguruma5php-6.9.7.1-1.el7.remi.x86_64.rpm --no-check-certificate &> $dev_dir
    wget https://rpms.remirepo.net/enterprise/7/remi/x86_64/oniguruma5php-devel-6.9.7.1-1.el7.remi.x86_64.rpm --no-check-certificate &> $dev_dir
    rpm -ivh oniguruma5php-6.9.7.1-1.el7.remi.x86_64.rpm &> $dev_dir
    rpm -ivh oniguruma5php-devel-6.9.7.1-1.el7.remi.x86_64.rpm &> $dev_dir
#    yum install -y oniguruma5php-* &> $dev_dir
    sleep 3
    if_test ${messages[3]} | tee -a $php_log
}
dec_tar(){        #解压PHP安装包
    delimiter | tee -a $php_log
    echoinfo ${messages[4]} | tee -a $php_log
    tar -zxvf $php_tar -C $src_dir/ &> $dev_dir
    sleep 3
    if_test ${messages[4]} | tee -a $php_log
}
precom(){        #PHP预编译
    delimiter | tee -a $php_log
    echoinfo ${messages[5]} | tee -a $php_log
    cd $src_dir/php-8.1.9/
    ./configure $dec_pack &>> $php_log
    sleep 3
    if_test ${messages[5]} | tee -a $php_log
}
comp(){        #PHP编译
    delimiter | tee -a $php_log
    echoinfo ${messages[6]} | tee -a $php_log
    cd $src_dir/php-8.1.9/
    make -j `grep "processor" /proc/cpuinfo | wc -l` &>> $php_log
    sleep 3
    if_test ${messages[6]} | tee -a $php_log
}
com_ins(){    #PHP编译安装
    delimiter | tee -a $php_log
    echoinfo ${messages[7]} | tee -a $php_log
    cd $src_dir/php-8.1.9/
    make install &>> $php_log
    sleep 3
    if_test ${messages[7]} | tee -a $php_log
}
gen_profile(){    #生成配置文件
    delimiter | tee -a $php_log
    echoinfo ${messages[8]} | tee -a $php_log
    useradd -M -s /sbin/nologin nginx &>> $php_log
    cd $php_dir/etc/
    cp php-fpm.conf.default php-fpm.conf
    cp $src_dir/php-8.1.9/php.ini-production $php_dir/etc/php.ini
    cp $php_dir/etc/php-fpm.d/www.conf.default $aaa
    sed -i "/;listen.owner = nobody/c \;listen.owner = nginx" $aaa
    sed -i "/;listen.group = nobody/c \;listen.group = nginx" $aaa
    sed -i "/user = nobody/c \user = nginx" $aaa
    sed -i "/group = nobody/c \group = nginx" $aaa
#    sed -i "/            index  index.html index.htm;/c \            index  index.php index.html index.htm;" /usr/local/nginx/conf/nginx.conf
    sleep 3
    if_test ${messages[8]} | tee -a $php_log
}
set_start(){    #PHP启动管理
    delimiter | tee -a $php_log
    echoinfo ${messages[9]} | tee -a $php_log
    cd
    cp $src_dir/php-8.1.9/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
    cd
    chmod a+x /etc/init.d/php-fpm
    chkconfig --add php-fpm &> $dev_dir
    chkconfig php-fpm on &> $dev_dir
    /etc/init.d/php-fpm start &> $dev_dir
    netstat -antup | grep php-fpm &>> $php_log
    ps -ef | grep grep php-fpm &>> $php_log
    /etc/init.d/php-fpm stop &> $dev_dir
    systemctl restart php-fpm &>> $php_log
    netstat -antup | grep php-fpm &>> $php_log
    ps -ef | grep grep php-fpm &>> $php_log
    sleep 3
    if_test ${messages[9]} | tee -a $php_log
}
########################################
echo "################BEGIN!!!$(date "+%F %T")################" | tee -a $php_log
#调用函数
check_tar
wait
dep_tar
wait
ins_onigur
wait
dec_tar
wait
precom
wait
comp
wait
com_ins
wait
gen_profile
wait
set_start
wait
echo "################END!!!$(date "+%F %T")################" | tee -a $php_log
########################################
 

你可能感兴趣的:(PHP,shell脚本,集群搭建,php,开发语言,linux,centos,云计算)