zoukankan      html  css  js  c++  java
  • php编译安装及配置nginx解析php

    php编译安装

    1.依赖包

    #编译环境依赖包
    [root@localhost ~]# yum -y install gcc gcc-c++ glibc automake autoconf libtool
    make
    
    [root@localhost ~]# mkdir -p /usr/local/php7
    
    #编译php依赖库
    [root@localhost ~]# yum -y install libxslt-devel libjpeg libjpeg-devel libpng
    libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc
    glibc-devel glib2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs
    e2fsprogs-devel krb5-devel libidn libidn-devel openssl openssl-devel
    

    2.安装cmake

    [root@localhost ~]# cd /usr/local/src
    [root@localhost src]# wget
    https://github.com/Kitware/CMake/releases/download/v3.14.5/cmake-3.14.5.tar.gz
    
    [root@localhost src]# tar -zxvf cmake-3.14.5.tar.gz
    [root@localhost src]# cd cmake-3.14.5
    [root@localhost cmake-3.14.5]# ./bootstrap
    [root@localhost cmake-3.14.5]# gmake
    [root@localhost cmake-3.14.5]# gmake install
    
    [root@localhost cmake-3.14.5]# cmake -version
    

    3.安装libzip

    [root@localhost ~]# cd /usr/local/src
    [root@localhost src]# wget https://libzip.org/download/libzip-1.5.2.tar.gz
    [root@localhost src]# tar -zxvf libzip-1.5.2.tar.gz
    [root@localhost src]# cd libzip-1.5.2/
    [root@localhost libzip-1.5.2]# mkdir build
    [root@localhost libzip-1.5.2]# cd build
    [root@localhost build]# cmake ..
    [root@localhost build]# make -j2
    [root@localhost build]# make test
    [root@localhost build]# make install
    

    4.编译安装php-fpm

    [root@localhost build]# cd /usr/local/src
    [root@localhost src]# wget https://www.php.net/distributions/php-7.3.6.tar.gz
    
    [root@localhost src]# tar -zxvf php-7.3.6.tar.gz
    [root@localhost src]# cd php-7.3.6
    [root@localhost php-7.3.6]# ./configure 
    --prefix=/usr/local/php7 
    --with-config-file-path=/usr/local/php7 
    --with-config-file-scan-dir=/usr/local/php7/php.d 
    --enable-mysqlnd 
    --with-mysqli 
    --with-pdo-mysql 
    --enable-fpm 
    --with-fpm-user=nginx 
    --with-fpm-group=nginx 
    --with-gd 
    --with-iconv 
    --with-zlib 
    --enable-xml 
    --enable-shmop 
    --enable-sysvsem 
    --enable-inline-optimization 
    --enable-mbregex 
    --enable-mbstring 
    --enable-ftp 
    --with-openssl 
    --enable-pcntl 
    --enable-sockets 
    --with-xmlrpc 
    --enable-zip 
    --enable-soap 
    --without-pear 
    --with-gettext 
    --enable-session 
    --with-curl 
    --with-jpeg-dir 
    --with-freetype-dir 
    --enable-opcache
    
    
    #报错解决编译中off_t...问题
    [root@localhost php-7.3.6]# vim /etc/ld.so.conf
    # 添加如下几行
    /usr/local/lib64
    /usr/local/lib
    /usr/lib
    /usr/lib64
    # 使配置生效
    [root@localhost php-7.3.6]# ldconfig -v
    
    [root@localhost php-7.3.6]# make && make install
    

    5.php-fpm配置文件

    [root@localhost php-7.3.6]# cp /usr/local/src/php-7.3.6/php.ini-production
    /usr/local/php7/etc/php.ini
    
    [root@localhost php-7.3.6]# cd /usr/local/php7/etc
    [root@localhost etc]# cp php-fpm.conf.default php-fpm.conf
    #主配置文件
    [root@localhost etc]# vim /usr/local/php7/etc/php-fpm.conf
    pid=/usr/local/php7/var/run/php-fpm.pid		//添加修改
    
    
    [root@localhost etc]# cd /usr/local/php7/etc/php-fpm.d
    [root@localhost php-fpm.d]# cp www.conf.default nginx.conf
    子配置文件
    [root@localhost php-fpm.d]# vim /usr/local/php7/etc/php-fpm.d/nginx.conf
    [www.xxx.com]		#此处命名要与域名一直
    user = nginx
    group = nginx
    listen = 127.0.0.1:9000
    pm = dynamic
    pm.max_children = 100
    pm.start_servers = 20
    pm.min_spare_servers = 5
    pm.max_spare_servers = 35
    
    [root@localhost php-fpm.d]# /usr/local/php7/sbin/php-fpm
    [root@localhost ~]# ps aux | grep php-fpm
    
    
    

    6.添加php-fpm环境变量

    #配置php-fpm环境变量
    [root@localhost ~]# vim /etc/profile
    export PHP_HOME=/usr/local/php7
    export PATH=$PATH:$PHP_HOME/bin:$PHP_HOME/sbin
    
    [root@localhost ~]# source /etc/profile
    

    7.php-fpm加入systemd服务

    [root@localhost ~]# vim /lib/systemd/system/php-fpm.service
    [Unit]
    Description=php-fpm
    After=network.target
    [Service]
    Type=forking
    ExecStart=/usr/local/php7/sbin/php-fpm
    ExecStop=/bin/pkill -9 php-fpm
    PrivateTmp=true
    [Install]
    WantedBy=multi-user.target
    
    [root@localhost ~]# systemctl daemon-reload
    [root@localhost ~]# pkill php-fpm
    [root@localhost ~]# systemctl start php-fpm.service
    [root@localhost ~]# systemctl enable php-fpm.service
    [root@localhost ~]# systemctl list-units --type=service # 查看所有已启动的服务
    

    8.配置nginx解析php

    [root@localhost ~]# vim /etc/nginx/conf.d/nginx-php.conf
    server {
            listen 80;
            server_name www.zhangsan.com zhangsan.com;
            access_log /var/log/nginx/zhangsan-access.log main;
            error_log /var/log/nginx/zhangsan-error.log;
            location /{
                    root /var/www/zhangsan;
                    index index.php index.html index.htm;
                    deny 192.168.133.5;
                    allow all;
            }
    
    #        location /status{
    #        stub_status on;
    #        access_log off;
    #        }
    
    
            location ~ .php$
            {
                    include fastcgi_params;
                    fastcgi_pass 127.0.0.1:9000;
                    fastcgi_index index.php;
                    #fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name;
                    fastcgi_param SCRIPT_FILENAME //var/www/zhangsan$fastcgi_script_name;
            }
    
    }
    [root@localhost ~]# vim /var/www/zhangsan/index.php
    <?php
    phpinfo();
    ?>
    
    [root@localhost ~]# systemctl restart php-fpm.service
    [root@localhost ~]# ps -ef|grep php-fpm
    [root@localhost ~]# systemctl reload nginx
    [root@localhost ~]# systemctl status nginx
    
    
    

    9.客户端上测试

    [root@localhost ~]# curl www.zhangsan.com
    
    配置若有遗漏或错误,请评论留言。
  • 相关阅读:
    左偏树
    output html
    jsp web.xml
    mysql link db
    beamline
    jsp embend java into html / mix scriptlets and HTML
    StringTokenizer
    TreeSet
    centOS 显示中文
    request and response
  • 原文地址:https://www.cnblogs.com/BrokenEaves/p/15155395.html
Copyright © 2011-2022 走看看