zoukankan      html  css  js  c++  java
  • 自动安装php7(配置未优化版本)

    #!/bin/bash
    #by dxd in 2017-6
    #only suit for centos/aliyun os, and based on aliyun install script
    
    CURR_PATH=$(pwd)
    
    
    DOWNLOAD_LIBMCRYPT_URL=http://download.verymall.cn/libmcrypt-2.5.8.tar.gz
    DOWNLOAD_PHP7_URL=http://download.verymall.cn/php7.bz2
    DOWNLOAD_PHP_INI_URL=http://download.verymall.cn/php7.ini
    PHP_INSTALL_PATH=/alidata/server/php7
    PHP_FPM_PORT=9001
    
    
    function check_user()
    {
        if [ "$(whoami)" != "root" ] 
        then
            echo "please run as root"
            exit 1
        fi
    }
    
    function update_linux()
    {
        yum update && yum upgrade
        yum groupinstall "Development Tools"
        yum install gcc gcc-c++ pcre* openssl* gd-devel* zlib-devel pcre-devel libxml2-devel curl-devel
    }
    
    function check_curr_path_auth()
    {
        if [ ! -w $CURR_PATH ]
        then
            echo "current path has no write auth"
            exit 1
        fi
    }
    
    function is_curr_path_legal()
    {
        if [ "$(ls | grep install.sh)" == "" ]
        then
            echo "path is illegal"
            exit 1
        fi
    }
    
    function check_gcc()
    {
        which gcc > /dev/null 2>&1
        if [ "$?" != "0" ]
        then
            echo "please install gcc first"
            exit 1
        fi
    }
    
    function check_fpm_port()
    {
        if [ -n "$(lsof -i:$PHP_FPM_PORT)" ]
        then
            echo "PORT $PHP_FPM_PORT is occupied"
            exit 1
        fi
    }
    
    function check_alidata_path()
    {
        if [ ! -d /alidata ]
        then
            mkdir /alidata
        fi
    
        if [ ! -d /alidata/server ]
        then
            echo "alidata server has not been installed"
            exit 1
        fi
    
        mkdir $PHP_INSTALL_PATH
    }
    
    function install_dos2unix()
    {
        which dos2unix > /dev/null 2>&1
        if [ "$?" != "0" ]
        then
            yum install dos2unix
        fi
    }
    
    function download_and_install_libmcrypt()
    {
        if [ -a ./libmcrypt-2.5.8.tar.gz ] && [ -n "$(md5sum ./libmcrypt-2.5.8.tar.gz | grep 0821830d930a86a5c69110837c55b7da)" ]
        then
            echo "./libmcrypt-2.5.8.tar.gz exist"
        else
            rm -f ./libmcrypt-2.5.8.tar.gz
            wget $DOWNLOAD_LIBMCRYPT_URL
        fi
    
        tar -zxvf ./libmcrypt-2.5.8.tar.gz
        cd ./libmcrypt-2.5.8
        ./configure
        make
        make install
    
        cd $CURR_PATH
    }
    
    function update_ld()
    {
        if [ -z "$(cat /etc/ld.so.conf | grep /usr/local/lib)" ]
        then
            echo "/usr/local/lib" >> /etc/ld.so.conf
        fi
    
        if [ -z "$(cat /etc/ld.so.conf | grep /usr/lib64)" ]
        then
            echo "/usr/lib64" >> /etc/ld.so.conf
        fi
    
        ldconfig
    }
    
    function download_php7()
    {
        cd $CURR_PATH 
    
        if [ -a ./php7.bz2 ] && [ -n "$(md5sum ./php7.bz2 | grep fb88987cd0c7fefa527f2170a2617f78)" ]
        then
            echo "./php7.bz2 exist"
        else
            rm -f ./php7.bz2
            wget $DOWNLOAD_PHP7_URL
        fi
    
        #uncompress bz2 file
        tar -xvf ./php7.bz2 > /dev/null
    }
    
    function install_php7()
    {
        cd $CURR_PATH 
        cd ./php-7.1.6
    
        mkdir /usr/lib64/
        ln -s /usr/local/lib/libiconv.so.2 /usr/lib64/
    
        ./configure 
        --prefix=$PHP_INSTALL_PATH 
        --exec-prefix=$PHP_INSTALL_PATH 
        --bindir=$PHP_INSTALL_PATH/bin 
        --sbindir=$PHP_INSTALL_PATH/sbin 
        --includedir=$PHP_INSTALL_PATH/include 
        --libdir=$PHP_INSTALL_PATH/lib/php 
        --mandir=$PHP_INSTALL_PATH/php/man 
        --with-config-file-path=$PHP_INSTALL_PATH/etc 
        --with-mcrypt=/usr/include 
        --with-mhash 
        --with-openssl 
        --with-mysqli=shared,mysqlnd 
        --with-pdo-mysql=shared,mysqlnd 
        --with-gd 
        --with-iconv 
        --with-zlib 
        --enable-zip 
        --enable-inline-optimization 
        --disable-debug 
        --disable-rpath 
        --enable-shared 
        --enable-xml 
        --enable-bcmath 
        -enable-shmop 
        --enable-sysvsem 
        --enable-mbregex 
        --enable-mbstring 
        --enable-ftp 
        --enable-gd-native-ttf 
        --enable-pcntl 
        --enable-sockets 
        --with-xmlrpc 
        --enable-soap 
        --without-pear 
        --with-gettext 
        --enable-session 
        --with-curl 
        --with-jpeg-dir 
        --with-freetype-dir 
        --enable-opcache 
        --enable-fpm 
        --without-gdbm 
        --enable-fileinfo
    #    --disable-fileinfo
        
        make ZEND_EXTRA_LIBS='-liconv'
        make install
    }
    
    function config_php7()
    {
        if [ ! -a $PHP_INSTALL_PATH/etc/php-fpm.conf ]
        then
            cp $PHP_INSTALL_PATH/etc/php-fpm.conf.default $PHP_INSTALL_PATH/etc/php-fpm.conf
        fi
        
        if [ ! -a $PHP_INSTALL_PATH/etc/php-fpm.d/www.conf ]
        then
            cp $PHP_INSTALL_PATH/etc/php-fpm.d/www.conf.default $PHP_INSTALL_PATH/etc/php-fpm.d/www.conf
        fi
    
        if [ -z "$(cat $PHP_INSTALL_PATH/etc/php-fpm.conf | grep 127)" ]
        then
            echo "listen = 127.0.0.1:$PHP_FPM_PORT" >> $PHP_INSTALL_PATH/etc/php-fpm.conf
            echo "listen.backlog = -1" >> $PHP_INSTALL_PATH/etc/php-fpm.conf
            echo "listen.owner = www" >> $PHP_INSTALL_PATH/etc/php-fpm.conf
            echo "listen.group = www" >> $PHP_INSTALL_PATH/etc/php-fpm.conf
            echo "listen.mode = 0666" >> $PHP_INSTALL_PATH/etc/php-fpm.conf
            echo "user = www" >> $PHP_INSTALL_PATH/etc/php-fpm.conf
            echo "group = www" >> $PHP_INSTALL_PATH/etc/php-fpm.conf
        fi
    
        if [ ! -a $PHP_INSTALL_PATH/etc/php.ini ]
        then
            wget $DOWNLOAD_PHP_INI_URL -O $PHP_INSTALL_PATH/etc/php.ini
        fi
    }
    
    function start_php_fpm()
    {
        $PHP_INSTALL_PATH/sbin/php-fpm
    }
    
    check_user
    update_linux
    is_curr_path_legal
    check_curr_path_auth
    check_gcc
    check_fpm_port
    check_alidata_path
    install_dos2unix
    download_and_install_libmcrypt
    update_ld
    download_php7
    install_php7
    config_php7
    start_php_fpm
    
    echo "php7 install successfully"
    exit 0

    博主附后:

    启动php7 phpfpm
    /alidata/server/php7/sbin/php-fpm


    关闭php7 phpfpm
    lsof -i :9001 | cut -d " " -f 2 | xargs kill -9

    for i in $(lsof -i :9001 | cut -d " " -f 2)
    do
    kill $i
    done

  • 相关阅读:
    Running ASP.NET Applications in Debian and Ubuntu using XSP and Mono
    .net extjs 封装
    ext direct spring
    install ubuntu tweak on ubuntu lts 10.04,this software is created by zhouding
    redis cookbook
    aptana eclipse plugin install on sts
    ubuntu open folderpath on terminal
    ubuntu install pae for the 32bit system 4g limited issue
    EXT Designer 正式版延长使用脚本
    用 Vagrant 快速建立開發環境
  • 原文地址:https://www.cnblogs.com/ddcoder/p/7062311.html
Copyright © 2011-2022 走看看