zoukankan      html  css  js  c++  java
  • centos7.5环境下编译安装php7.0.30并安装redis和mongo扩展

    1.安装php7.0.30的脚本
    
    # vim install_php.sh
    
    #!/bin/bash
    # 安装基本依赖
    yum install -y gcc gcc-c++ htop telnet iotop iptraf iftop make logrotate xinetd ntsysv  sysstat perl autoconf libjpeg libjpeg-devel libpng libpng-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel e2fsprogs e2fsprogs-devel krb5-devel libidn libidn-devel libxml2 libxml2-devel libxslt-devel libevent-devel libtool libtool-ltdl bison  ntpdate  patch vim wget openssh-clients bind-utils
    yum -y install libicu-devel libpng12 libpng12-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel mysql pcre-devel  libxslt-devel  curl-devel
    
    ## zlib
    echo "*******************install zlib start*******************"
    cd /usr/local/src && wget http://www.zlib.net/zlib-1.2.11.tar.gz
    tar -xvzf zlib-1.2.11.tar.gz
    cd zlib-1.2.11
    ./configure --prefix=/usr/local/zlib
    make && make install
    ls -l /usr/local/zlib
    echo "*******************install zlib end*******************"
    
    ## openssl
    
    echo "*******************install openssl start*******************"
    cd /usr/local/src && wget https://www.openssl.org/source/openssl-1.1.0e.tar.gz --no-check-certificate
    tar -xzf openssl-1.1.0e.tar.gz
    cd openssl-1.1.0e/
    ./config --prefix=/usr/local/openssl
    ./config -t
    make && make install
    ls /usr/local/bin/openssl  -l
    echo "*******************install openssl end*******************"
    
    ## freetype
    echo "*******************install freetype start*******************"
    cd /usr/local/src && wget https://download.savannah.gnu.org/releases/freetype/freetype-2.4.0.tar.gz --no-check-certificate
    tar -zxvf freetype-2.4.0.tar.gz
    cd freetype-2.4.0/
    ./configure --prefix=/usr/local/freetype
    make && make install
    echo "*******************install freetype end*******************"
    
    ## PHP安装
    echo "*******************install php-7.0.30 start*******************"
    
    cd /usr/local/src && wget http://cn2.php.net/distributions/php-7.0.30.tar.gz
    tar -zxvf php-7.0.30.tar.gz
    cd php-7.0.30
    ./configure  
    --prefix=/usr/local/php7.0.30 
    --mandir=/usr/local/php7.0.30/share/man  
    --infodir=/usr/local/php7.0.30/share/info  
    --enable-fpm 
    --enable-mbstring 
    --enable-zib 
    --enable-bcmath 
    --enable-opcache 
    --enable-pcnt 
    --enable-soa 
    --enable-calenda 
    --enable-exif 
    --enable-ftp 
    --enable-intl 
    --with-curl 
    --with-gd 
    --with-jpeg-dir=/usr/local/zlib 
    --with-png-dir=/usr/local/zlib 
    --with-mysql 
    --with-pdo_mysql 
    --with-mcrypt 
    --with-freetype-dir=/usr/local/freetype 
    --with-zlib=/usr/local/zlib 
    --with-openssl
    
    make && make install
    if [ $? != 0 ];then
    exit 7
    fi
    ln -s /usr/local/php7.0.30  /usr/local/php
    cp /usr/local/src/php-7.0.30/php.ini-development /usr/local/php7.0.30/lib/php.ini
    cp /usr/local/php7.0.30/etc/php-fpm.conf.default /usr/local/php7.0.30/etc/php-fpm.conf
    cp  /usr/local/php7.0.30/etc/php-fpm.d/www.conf.default /usr/local/php7.0.30/etc/php-fpm.d/www.conf
    
    echo "*******************install php-7.0.30 end*******************"
    
    ## Mongo扩展
    echo "*******************install Mongo扩展 start*******************"
    cd /usr/local/src && wget http://pecl.php.net/get/mongodb-1.5.2.tgz
    tar -zxvf mongodb-1.5.2.tgz
    cd mongodb-1.5.2/
    /usr/local/php7.0.30/bin/phpize
    ./configure --with-php-config=/usr/local/php7.0.30/bin/php-config
    make && make install
    ls /usr/local/php7.0.30/lib/php/extensions/no-debug-non-zts-20151012/
    
    echo "*******************install Mongo扩展 end*******************"
    
    
    ## Redis扩展
    echo "*******************install Redis扩展 start*******************"
    cd /usr/local/src && wget http://pecl.php.net/get/redis-4.0.2.tgz
    tar -zxvf redis-4.0.2.tgz
    cd redis-4.0.2/
    /usr/local/php7.0.30/bin/phpize
    ./configure --with-php-config=/usr/local/php7.0.30/bin/php-config
    make && make install
    ls /usr/local/php7.0.30/lib/php/extensions/no-debug-non-zts-20151012/
    echo "*******************install Redis扩展 end*******************"
    
    ## tideways扩展
    echo "*******************install tideways扩展 start*******************"
    cd /usr/local/src && wget https://s3-eu-west-1.amazonaws.com/tideways/extension/5.0.18/tideways-php-5.0.18-x86_64.tar.gz --no-check-certificate
    tar -zxf tideways-php-5.0.18-x86_64.tar.gz
    cd tideways-5.0.18
    /usr/local/php7.0.30/bin/phpize
    cp tideways-php-7.0.so /usr/local/php7.0.30/lib/php/extensions/no-debug-non-zts-20151012/
    cd /usr/local/php7.0.30/lib/php/extensions/no-debug-non-zts-20151012/
    mv tideways-php-7.0.so tideways.so
    echo "*******************install tideways扩展 end*******************"
    
    ## ioncube_loaders 扩展
    echo "*******************install ioncube_loaders start*******************"
    cd /usr/local/src && wget https://downloads.ioncube.com/loader_downloads/ioncube_loaders_lin_x86-64.tar.gz --no-check-certificate
    tar -zxvf  ioncube_loaders_lin_x86-64.tar.gz
    cd ioncube/
    ls
    cp ioncube_loader_lin_7.0.so  /usr/local/php7.0.30/lib/php/extensions/no-debug-non-zts-20151012/
    echo "*******************install ioncube_loaders end*******************"
    
    2.修改配置文件
    
    # php.ini配置文件
    
    # vim /usr/local/php7.0.30/lib/php.ini
    [dba]
    
    extension_dir=/usr/local/php/lib/php/extensions/no-debug-non-zts-20151012/
    extension=redis.so
    extension=mongodb.so
    
    [tideways]
    extension=tideways.so
    ;不需要自动加载,在程序中控制就行
    tideways.auto_prepend_library=0
    ;频率设置为100,在程序调用时能改
    tideways.sample_rate=100
    
    [ionCube Loader]
    zend_extension=ioncube_loader_lin_7.0.so
    
    # php-fpm.conf文件
    [root@eus_filmora_file01:/usr/local/php]# egrep -v '^$|^;' /usr/local/php/etc/php-fpm.conf
    [global]
     process.max = 256
    rlimit_files = 65535
    events.mechanism = epoll
    include=/usr/local/php7.0.30/etc/php-fpm.d/*.conf
    
    
    sed -i 's#user = nobody#user = apache#g' /usr/local/php7.0.30/etc/php-fpm.d/www.conf
    sed -i 's#group = nobody#group = users#g' /usr/local/php7.0.30/etc/php-fpm.d/www.conf
    
    # www.conf文件
    [root@eus_filmora_file01:/usr/local/php]# egrep -v '^$|^;' /usr/local/php/etc/php-fpm.d/www.conf
    [www]
    user = apache
    group = users
    listen = 127.0.0.1:9000
    pm = dynamic
    pm.max_children = 500
    pm.start_servers = 32
    pm.min_spare_servers = 16
    pm.max_spare_servers = 64
    pm.process_idle_timeout = 10s;
    pm.max_requests = 10240
    request_terminate_timeout = 100
    rlimit_core = 8
    
    
    ##################启动脚本
    
    # 生成软连接
    [root@eus_filmora_file02:/usr/local/src]# rm -f /usr/local/php
    [root@eus_filmora_file02:/usr/local/src]# ln -s /usr/local/php7.0.30/ /usr/local/php
    
    [root@eus_filmora_file01:/usr/local/src/tideways-5.0.18]# vim /etc/init.d/php-fpm
    #! /bin/sh
    
    ### BEGIN INIT INFO
    # Provides:          php-fpm
    # Required-Start:    $remote_fs $network
    # Required-Stop:     $remote_fs $network
    # Default-Start:     2 3 4 5
    # Default-Stop:      0 1 6
    # Short-Description: starts php-fpm
    # Description:       starts the PHP FastCGI Process Manager daemon
    ### END INIT INFO
    
    prefix=/usr/local/php
    exec_prefix=${prefix}
    
    php_fpm_BIN=${exec_prefix}/sbin/php-fpm
    php_fpm_CONF=${prefix}/etc/php-fpm.conf
    php_fpm_PID=${prefix}/var/run/php-fpm.pid
    
    
    php_opts="--fpm-config $php_fpm_CONF --pid $php_fpm_PID"
    
    
    wait_for_pid () {
        try=0
    
        while test $try -lt 35 ; do
    
            case "$1" in
                'created')
                if [ -f "$2" ] ; then
                    try=''
                    break
                fi
                ;;
    
                'removed')
                if [ ! -f "$2" ] ; then
                    try=''
                    break
                fi
                ;;
            esac
    
            echo -n .
            try=`expr $try + 1`
            sleep 1
    
        done
    
    }
    
    case "$1" in
        start)
            echo -n "Starting php-fpm "
    
            $php_fpm_BIN --daemonize $php_opts
    
            if [ "$?" != 0 ] ; then
                echo " failed"
                exit 1
            fi
    
            wait_for_pid created $php_fpm_PID
    
            if [ -n "$try" ] ; then
                echo " failed"
                exit 1
            else
                echo " done"
            fi
        ;;
    
        stop)
            echo -n "Gracefully shutting down php-fpm "
    
            if [ ! -r $php_fpm_PID ] ; then
                echo "warning, no pid file found - php-fpm is not running ?"
                exit 1
            fi
    
            kill -QUIT `cat $php_fpm_PID`
    
            wait_for_pid removed $php_fpm_PID
    
            if [ -n "$try" ] ; then
                echo " failed. Use force-quit"
                exit 1
            else
                echo " done"
            fi
        ;;
    
        force-quit)
            echo -n "Terminating php-fpm "
    
            if [ ! -r $php_fpm_PID ] ; then
                echo "warning, no pid file found - php-fpm is not running ?"
                exit 1
            fi
    
            kill -TERM `cat $php_fpm_PID`
    
            wait_for_pid removed $php_fpm_PID
    
            if [ -n "$try" ] ; then
                echo " failed"
                exit 1
            else
                echo " done"
            fi
        ;;
    
        restart)
            $0 stop
            $0 start
        ;;
    
        reload)
    
            echo -n "Reload service php-fpm "
    
            if [ ! -r $php_fpm_PID ] ; then
                echo "warning, no pid file found - php-fpm is not running ?"
                exit 1
            fi
    
            kill -USR2 `cat $php_fpm_PID`
    
            echo " done"
        ;;
    
        *)
            echo "Usage: $0 {start|stop|force-quit|restart|reload}"
            exit 1
        ;;
    
    esac
    
    #######################
    
    
    测试的域名
    # vim /usr/local/nginx/conf/vhost.d/film.chinasoft.com.conf
    server {
            listen 80;
    
            server_name     film.chinasoft.com;
    
            proxy_connect_timeout 1800s;
            proxy_read_timeout 1800s;
            proxy_send_timeout 1800s;
                access_log      /data/www/logs/nginx_log/access/film.chinasoft.com_access.log main ;
            access_log on;
                error_log       /data/www/logs/nginx_log/error/film.chinasoft.com_error.log ;
                root            /data/www/vhosts/film.chinasoft.com/httpdocs/api/public ;
                index           index.html index.shtml index.php ;
            error_page  404 403              /404.html;    
            
                location / {
                        index  index.php index.html index.htm;
                        try_files $uri $uri/ /index.php?$query_string;
                }
    
                location ~ .php$ {
                        #fastcgi_pass   unix:/tmp/php-cgi.sock;
                        fastcgi_pass 127.0.0.1:9000;
                        fastcgi_index  index.php;
                        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                        include        fastcgi_params;
                }
    
            
                location ^~ /logs/
                {
                        deny all;
                }
    
        }
    
    server {
            listen 443;
            ssl on;
    
            ssl_certificate         cert2016/chinasoft_com.crt;
            ssl_certificate_key     cert2016/chinasoft_com.key;
            ssl_dhparam     cert2016/dh_2048.pem;
    
            ssl_session_timeout     5m;
            ssl_protocols   TLSv1 TLSv1.1 TLSv1.2;
    
            ssl_ciphers     "ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:!AES128-GCM-SHA256:!AES256-GCM-SHA384:!AES128-SHA256:!AES256-SHA256:!AES128-SHA:!AES256-SHA:AES:!CAMELLIA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!aECDH:!EDH-DSS-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA";
    
            ssl_prefer_server_ciphers       on;
    
            server_name     film.chinasoft.com;
            access_log      /data/www/logs/nginx_log/access/film.chinasoft.com_access.log main ;
            error_log       /data/www/logs/nginx_log/error/film.chinasoft.com_error.log ;
    
            root            /data/www/vhosts/film.chinasoft.com/httpdocs/api/public ;
            index           index.html index.shtml index.php ;
            error_page  404 403              /404.html;
    
    
    
            location / {
                    index  index.php index.html index.htm;
                    try_files $uri $uri/ /index.php?$query_string;
            }
    
            location ~ .php$ {
                    
                    fastcgi_pass 127.0.0.1:9000;
                    fastcgi_index  index.php;
                    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                    include        fastcgi_params;
            }           
    
    
    }
    
    # 创建测试页面
    [root@eus_filmora_file01:/usr/local/php]# mkdir -p /data/www/vhosts/film.chinasoft.com/httpdocs/api/public
    [root@eus_filmora_file01:/usr/local/php]# echo "<?php echo phpinfo(); ?>"> /data/www/vhosts/film.chinasoft.com/httpdocs/api/public/index.php

     # php7.0.30安装mysqli扩展
    # 获取源码
    # wget https://www.php.net/distributions/php-7.0.30.tar.gz
    tar xf php-7.0.30.tar.gz
    cd php-7.0.30/ext/mysqli
    /usr/local/php7.0.30/bin/phpize
    # 编译扩展
    ./configure --prefix=/usr/local/mysqli --with-php-config=/usr/local/php7.0.30/bin/php-config --with-mysqli=/usr/local/mysql-5.7.23-el7-x86_64/bin/mysql_config
    make && make install

    Installing shared extensions:     /usr/local/php7.0.30/lib/php/extensions/no-debug-non-zts-20151012/
    Installing header files:          /usr/local/php7.0.30/include/php/

    # ll /usr/local/php7.0.30/lib/php/extensions/no-debug-non-zts-20151012/
    total 5304
    -rwxr-xr-x 1 root root  729240 Dec 13 00:33 mysqli.so
    -rwxr-xr-x 1 root root 1993656 Nov 20  2018 opcache.a
    -rwxr-xr-x 1 root root  928360 Nov 20  2018 opcache.so
    -rwxr-xr-x 1 root root 1771528 Nov 20  2018 redis.so


    # 添加mysqli扩展
    # vim /usr/local/php7.0.30/etc/php.ini

    [dba]
    extension_dir=/usr/local/php7.0.30/lib/php/extensions/no-debug-non-zts-20151012/
    extension=mysqli.so

    # php -m
    [PHP Modules]
    bcmath
    calendar
    Core
    ctype
    curl
    date
    dom
    exif
    fileinfo
    filter
    ftp
    gd
    hash
    iconv
    intl
    json
    libxml
    mbstring
    mcrypt
    mysqli

    [opcache]
    zend_extension=/usr/local/php7.0.30/lib/php/extensions/no-debug-non-zts-20131226/opcache.so
    opcache.memory_consumption=2048
    opcache.interned_strings_buffer=8
    opcache.max_accelerated_files=4000
    opcache.revalidate_freq=60
    opcache.fast_shutdown=1
    opcache.enable_cli=1
    opcache.enable=1
    opcache.force_restart_timeout=1800
    opcache.optimization_level=1
  • 相关阅读:
    Python logging根据时间创建日志文件
    ORACLE Merge into 使用
    go安装goctl
    Oracle 行转列
    ORACLE with as查询优化
    Linux环境使用Docker安装MongoDb
    Linux环境使用Docker安装MySql
    Docker基础操作
    Linux基础命令
    Ansible自动化运维介绍
  • 原文地址:https://www.cnblogs.com/reblue520/p/9689622.html
Copyright © 2011-2022 走看看