php扩展模块安装的脚本

2021-03-28 16:26

阅读:670

标签:signal   style   www   src   bsp   exit   rpm   一个个   load   

有些在源码里面有的扩展,需要一个个安装很麻烦,写个脚本一键安装

#!/usr/bin/python
# -*- coding: utf-8 -*-
# 2020-3-20
# author:hhh

import os
import sys
import subprocess
import signal

install_phpmode_list = [curl,wddx,bcmath,sysvsem,sysvshm]

def syscmd(cmd_line):
    if len(cmd_line)  0:
        return -1,None
    try:
        p = subprocess.Popen(cmd_line, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        try:
            outs, errs = p.communicate()
            retval = p.returncode
        except subprocess.TimeoutExpired:
            os.kill(p.pid, signal.SIGKILL)
            outs, errs = p.communicate()
            retval = p.returncode
        return retval, outs.decode("utf-8", "replace"), errs.decode()
    except Exception as e:
        return -1, None, None

def yum_install(rpm):
    check_rpm = rpm -qa |grep -w %s % rpm
    ret,output,err = syscmd(check_rpm)
    if ret == 1:
        install_cmd = yum -y install %s % rpm
        ret,output,err = syscmd(install_cmd)
        if ret == 0:
            print(install %s success... % rpm)
            return True
        else:
            print(install %s faild... % rpm)
            sys.exit(1)
    else:
        print(skip install %s  % rpm)
        return True

def download_source(version):
    wegt = wget -P /usr/local/src http://www.php.net/distributions/%s.tar.gz%version
    ret1, output1, err1 = syscmd(wegt)
    if ret1 == 0:
        print(wget %s success!%version)
        tar = tar zxvf /usr/local/src/%s.tar.gz%version
        ret2, output2, err2 = syscmd(tar)
        if ret2 == 0:
            print(tar zxvf %s success!%version)
        else:
            print(tar failed!,err2)
            sys.exit(1)
    else:
        print(wget failed!,err1)
        sys.exit(1)


def php_mod(install_php_mod):
    ret1, output1, err1 = syscmd(/usr/local/php72/bin/php -m | grep -w %s%install_php_mod)
    ret2, output2, err2 = syscmd(ls /usr/local/src/php-7.2.11/ext |grep -w %s %install_php_mod)
    if ret1 == 0 and %s%install_php_mod in output1:
        print(php mode %s is installed!%install_php_mod)
    elif ret1 == 1 and ret2 == 0 and %s%install_php_mod in output2:
        os.chdir(/usr/local/src/php-7.2.11/ext/%s%install_php_mod)
        phpize = /usr/local/php72/bin/phpize
        ret3, output3, err3 = syscmd(phpize)
        if ret3 == 0:
            configure = ./configure --with-php-config=/usr/local/php72/bin/php-config && make && make install
            ret4, output4, err4 = syscmd(configure)
            if ret4 == 0:
                echo_so ="echo ‘extension = %s.so\n‘ >>/usr/local/php72/etc/php.ini"%install_php_mod
                ret5, output5, err5 = syscmd(echo_so)
                if ret5 == 0:
                    print(install %s success!%install_php_mod)
                else:
                    print(echo failed!,err5)
                    sys.exit(1)
            else:
                print(configure failed!,err4)
                sys.exit(1)
        else:
            print(phpize failed,err3)
            sys.exit(1)
    else:
        print(%s php mode not in source!%install_php_mod)

def main():
    yum_install(php72)
    yum_install(libxml2)
    yum_install(libxml2_devel)
    download_source(php-7.2.11)
    for install_php_mod in install_phpmode_list:
        php_mod(install_php_mod)


if __name__ == __main__:
    main()

 

php扩展模块安装的脚本

标签:signal   style   www   src   bsp   exit   rpm   一个个   load   

原文地址:https://www.cnblogs.com/guantou1992/p/12618443.html


评论


亲,登录后才可以留言!