• 编译装php7.2 && nginx-1.14


    环境准备

    # cat /etc/centos-release

    CentOS Linux release 7.6.1810 (Core)

    # uname -r

    3.10.0-957.el7.x86_64

    # getenforce

    Disabled

    # systemctl status firewalld.service

    ● firewalld.service - firewalld - dynamic firewall daemon

       Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)

       Active: inactive (dead)

         Docs: man:firewalld(1)

    解决依赖关系

    # yum install -y gcc gcc-c++  make zlib zlib-devel pcre pcre-devel  libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers libXpm-devel postgresql-devel re2c libxslt libxslt-devel

    #这里要配置好epel源  re2c是epel源软件。

    安装libiconv 字符编码强制转换

    # wget https://ftp.gnu.org/pub/gnu/libiconv/libiconv版本号  #地址随时变动

    # tar xf libiconv-1.15.tar.gz

    # cd libiconv-1.15/

    # ./configure --prefix=/usr/local/libiconv

    # make && make install

    php7.2下载地址

    https://www.php.net/downloads.php  #地址可能会变动,找到php-7.2.16.tar.gz

    # tar xf php-7.2.16.tar.gz

    # cd php-7.2.16

    创建用户

    groupadd nginx

    useradd -r -g nginx -s /bin/false -M nginx

    编译安装php

    ./configure  --prefix=/application/php-7.2.16 --with-libxml-dir=/usr --with-curl --disable-rpath --with-xsl --with-jpeg-dir --with-png-dir --with-pdo-mysql  --with-mysqli --with-xmlrpc --with-zlib --enable-sysvsem --enable-mbregex --with-openssl --enable-sockets --enable-fpm --with-iconv-dir=/usr/local/libiconv --enable-bcmath --with-mhash --enable-inline-optimization --enable-pcntl --with-gd --with-fpm-user=nginx  --with-fpm-group=nginx --enable-opcache --enable-soap --enable-mbstring --enable-xml --with-pgsql --enable-calendar --enable-sysvshm --enable-exif --with-pcre-regex --with-zlib-dir --with-pdo-pgsql --with-freetype-dir --with-xpm-dir=/usr --with-gettext --with-libdir=/lib/x86_64-linux-gnu/ --with-freetype-dir --enable-shmop --enable-short-tags  --enable-static  --enable-ftp 

    # 部分安装参数说明:测试中发现7.2不提供压缩功能,所以有些类似的编译参数就删除了。

      --prefix=/application/php-7.2.16               #编译安装目录

    #  --with-pdo-mysql=mysqlnd                      #mysql扩展,php已经不支持了,这里已经改为mysqli扩展了,后面会提到,如果没有安装的,后边又编译安装方法

      --with-iconv-dir=/usr/local/libiconv           #字符编码强制转换

      --with-freetype-dir                          # 打开对freetype字体库的支持

      --with-jpeg-dir                             # 打开对jpeg图片的支持

      --with-png-dir                              # 打开对png图片的支持

      --with-zlib                                  # 打开zlib库的支持

      --with-libxml-dir=/usr                     # 打开libxml2库的支持

      --enable-xml                                 # 开启xml

      --disable-rpath                              # 关闭额外的运行库文件

      --enable-bcmath                            # 打开图片大小调整,用到zabbix监控的时候用到了这个模块

      --enable-shmop                             # 允许PHP读取、写入、创建和删除Unix共享内存段的函数集。

      --enable-sysvsem                           # 处理相关的IPC函数

      --enable-inline-optimization              # 优化线程

      --with-curl                                  # 打开curl浏览工具的支持

      --enable-mbregex               # 此配置项用于禁用具有多字节字符支持的正则表达式函数

      --enable-fpm                 # 打上PHP-fpm 补丁后才有这个参数。CGI方式安装的启动程序

      --enable-mbstring                          # 多字节,字符串的支持

      --with-gd                                  # 打开gd库的支持

      --with-openssl                       # openssl的支持,加密传输https时用到的

      --with-mhash                               #  mhash算法扩展

      --enable-pcntl                      # freeTDS需要用到的,可能是链接mssql 才用到

      --enable-sockets                           # 打开 sockets 支持

      --with-xmlrpc                              # 打开xml-rpc的c语言

      --enable-soap                        # SOAP扩展用来编写SOAP服务端和客户端

      --enable-short-tags                     # 短标记

      --enable-static                            # 生成静态链接库

      --with-xsl                    #打开XSLT文件支持,扩展了libXML2库 ,需要libxslt软件

      --with-fpm-user=nginx                        #用户名

      --with-fpm-group=nginx                   #用户组

      --enable-ftp                               # 打开ftp的支持

      --enable-opcache=no                       # 性能加速

    编译安装

    # make && make install

    # 创建软连接

    # ln -s /绝对路径/php-7.2.16 /绝对路径/php

    配置php

    注:目前位置在源码包解压目录

    # cp php.ini-production /application/php/php.ini

    # 配置php启动为systemctl管理(php编译安装个性化的编写好了systemctl文件复制到systemctl目录即可使用)

    cp /php-7.2.16/sapi/fpm/php-fpm.service /usr/lib/systemd/system/php-fpm.service

    注:切换至安装目录

    修改 php.ini 文件 设置 expose_php = Off
    vim /application/php/etc/php.ini
    找到 expose_php = On
    改为 expose_php = Off

    # cd /application/php/etc/

    # cp php-fpm.conf.default php-fpm.conf

    # vim php-fpm.conf

    去掉 pid = run/php-fpm.pid 前面的分号

    # cd php-fpm.d/

    # cp www.conf.default www.conf

    #  vim www.conf

    修改user和group的用户为当前用户(也可以不改,默认会添加nobody这个用户和用户组

    # sed -i 's#user = www#user = nginx#g;s#group = www#group = nginx#g' /application/php-5.5.32/etc/php-fpm.conf

    启动php-fpm

    # /etc/init.d/php-fpm start        #php-fpm启动命令

    # /etc/init.d/php-fpm stop         #php-fpm停止命令

    # /etc/init.d/php-fpm restart        #php-fpm重启命令

    # ps -ef | grep php 或者 ps -A | grep -i php  #查看是否已经成功启动PHP

     

    安装mysqli扩展

    注:默认在源码安装包中就有mysqli扩展包

    # cd /源码包位置/php-7.2.16/ext/mysqli

    # /php安装位置/bin/phpize   # 侦测环境建立configure文件

    # ./configure --with-php-config=/application/php/bin/php-config

    # make &&  make install

    # ls /application/php-7.2.16/lib/php/extensions/no-debug-non-zts-20170718/  # 此地址就是安装后的mysqli的扩展了。

    mysqli.so    # mysqli扩展文件

    # vim php.ini  # 修改php.ini 配置文件

    找到extension字段,在下方添加mysqli扩展位置

    extension = /application/php/lib/php/extensions/no-debug-non-zts-20170718/mysqli.so

    # 重启php-fpm和nginx通过phpinfo();查看安装的安装的扩展,效果如下

    # 下边的页面需要等nginx配置好后才能正常访问到

    # vim /nginx安装目录/html/test_info.php

    <?php

    phpinfo();

    ?>

     

     

     

     

     

    编译安装nginx

    # 将下载好的nginxnginx-1.14.2.tar.gz压缩包解压 #用上面创建的nginx用作为启动用户

    注:在后期添加模块的时候只需要重新make即可,不要make install后者会覆盖前者,即指覆盖安装的意思。

    # cd /nginxnginx-1.14.2

    # ./configure

    --prefix=/application/nginx-1.14.2     # 编译安装位置

    --user=nginx --group=nginx         # 启动用户组和用户

    --with-http_stub_status_module      # 用于查看Nginx的一些状态信息

    --with-http_ssl_module              # 添加ssl模块

    # make && make install

    # ln -s /绝对路径/nginxnginx-1.14.2 /绝对路径/nginx

    # cd /nginx安装目录/nginx/conf/

    # 精简nginx配置文件

    # egrep -v '^$|#' nginx.conf.default > nginx.conf

    # cat nginx.conf

    worker_processes  1;

    events {

        worker_connections  1024;

    }

    http {

        include       mime.types;

        default_type  application/octet-stream;

        sendfile        on;

        keepalive_timeout  65;

        server {

            listen       80;

            server_name  localhost;

            location / {

                root   html;

                index  index.html index.htm;

            }

            error_page   500 502 503 504  /50x.html;

            location = /50x.html {

                root   html;

            }

    # 下边是php解析配置部分

            location ~ .php$ {

                root           html;

                fastcgi_pass   127.0.0.1:9000;

                fastcgi_index  index.php;

                fastcgi_param  SCRIPT_FILENAME  /application/nginx/html$fastcgi_script_name;

                include        fastcgi_params;

            }

     

        }

    }

    启动nginx

    # /绝对路径/nginx           # 启动nginx

    # /绝对路径/nginx/ -c    # 指定配置文件,来取代默认的配置文件

    # /绝对路径/nginx -t     # 检查配置文件 每次nginx配置文件变更,都检查一次

    # /绝对路径/nginx -s reload   # 平滑重启

    # /绝对路径/nginx -s stop     # 停止nginx

    配置PATH环境  #注意符号,空格等

    # export PATH=/usr/local/nginx/sbin:$PATH

    # echo "export PATH=/application/nginx/sbin:$PATH" >>/root/.bash_profile

    # source /root/.bash_profile

    查看进程

    # ps -ef |grep -E 'nginx|php'

    root       8806      1  0 21:41 ?        00:00:00 nginx: master process nginx

    nginx      8807   8806  0 21:41 ?        00:00:00 nginx: worker process

    root       9244      1  0 21:59 ?        00:00:00 php-fpm: master process (/application/php-7.2.16/etc/php-fpm.conf)

    nginx      9245   9244  0 21:59 ?        00:00:00 php-fpm: pool www

    nginx      9246   9244  0 21:59 ?        00:00:00 php-fpm: pool www

    # netstat -antup|grep -E 'nginx|php'

    tcp        0      0 127.0.0.1:9000          0.0.0.0:*               LISTEN      9244/php-fpm: maste

    tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      8806/nginx: master 

    扩展整理,

    nginx反向代理

    # vim nginx.conf

    worker_processes  1;

    events {

        worker_connections  1024;

    }

    http {

        include       mime.types;

        default_type  application/octet-stream;

        sendfile        on;

        keepalive_timeout  65;

        upstream server_pools{

                 server 192.168.1.11:80;

        }

        server {

            listen       80;

            server_name  www.wordpress.com;

            location / {

                proxy_pass http://server_pools;

            }

            error_page   500 502 503 504  /50x.html;

            location = /50x.html {

                root   html;

            }

        }

    }

     

     通过php查看mysql5.7连接状态

    # vim test_mysql.php

    <?php

        $mysqli = new mysqli("主机地址","用户","密码","访问的库");

        if(!$mysqli)  {

            echo"database error";

        }else{

            echo"php env successful";

        }

        $mysqli->close();

    ?>

    # 效果展示

    负载均衡配置:

    # vim /application/nginx/conf/nginx.conf
    worker_processes 1;
    events {
    worker_connections 1024;
    }
    http {
    include mime.types;
    default_type application/octet-stream;
    sendfile on;
    keepalive_timeout 65;
    server {
    listen 80;
    server_name localhost;
    location / {
    root html/wordpress;
    index index.html index.htm index.php;
    }
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
    root html;
    }
    location ~ .*.(php|php7)?$ {
    root html/wordpress;
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    include fastcgi.conf;
    }

    }
    }

     

     

  • 相关阅读:
    测试用例
    HDU 5024 Wang Xifeng's Little Plot(枚举)
    HDU 1165 Eddy's research II
    java大数总结
    UVA 1646 Edge Case
    HDU 2553 N皇后问题
    【24题】试题库问题【网络流】
    YAPTCHA【数论】
    YAPTCHA【数论】
    YAPTCHA【数论】
  • 原文地址:https://www.cnblogs.com/lldsn/p/10611847.html
Copyright © 2020-2023  润新知