zoukankan      html  css  js  c++  java
  • centos7编译安装php7.2

    去官网下载php7.2安装包,选择一个结点下载:
    http://php.net/downloads.php

    下载:
    wget -ivh http://cn.php.net/distributions/php-7.2.12.tar.gz
    解压源码包:
    tar -zxf php-7.2.12.tar.gz

    安装编译php需要的依赖包:
    yum install gcc autoconf gcc-c++
    yum install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel readline readline-devel libxslt libxslt-devel
    yum install systemd-devel
    yum install openjpeg-devel

    添加www用户:
    创建群组:groupadd www
    创建一个用户,不允许登陆和不创主目录:useradd -s /sbin/nologin -g www -M www

    编译参数:

    开发环境:
        --enable-phpdbg
        --enable-dtrace
    生产环境:
        --disable-phpdbg
        --disable-dtrace

    ./configure
    --prefix=/usr/local/php
    --with-config-file-path=/usr/local/php/etc
    --with-zlib-dir
    --with-freetype-dir
    --enable-mbstring
    --with-libxml-dir=/usr
    --enable-xmlreader
    --enable-xmlwriter
    --enable-soap
    --enable-calendar
    --with-curl
    --with-zlib
    --with-gd
    --with-pdo-sqlite
    --with-pdo-mysql
    --with-mysqli
    --with-mysql-sock
    --enable-mysqlnd
    --disable-rpath
    --enable-inline-optimization
    --with-bz2
    --with-zlib
    --enable-sockets
    --enable-sysvsem
    --enable-sysvshm
    --enable-pcntl
    --enable-mbregex
    --enable-exif
    --enable-bcmath
    --with-mhash
    --enable-zip
    --with-pcre-regex
    --with-jpeg-dir=/usr
    --with-png-dir=/usr
    --with-openssl
    --enable-ftp
    --with-kerberos
    --with-gettext
    --with-xmlrpc
    --with-xsl
    --enable-fpm
    --with-fpm-user=php-fpm
    --with-fpm-group=php-fpm
    --with-fpm-systemd
    --disable-fileinfo

    执行编译:
    make && make install


    php-ini:
    源码包里面有配置文件:
        php.ini-development     测试开发环境
        php.ini-production         生产环境

    复制一份到指定的目录下(根据自己的情况选用,自己可以对比下这两个文件的差异):
    cp php.ini-production /usr/local/php/etc/php.ini

    php-fpm复制一份新的php-fpm配置文件: 
    cd /usr/local/php/etc
    cp php-fpm.conf.default php-fpm.conf
    vim php-fpm.conf

    配置错误日志:error_log = /usr/local/php/var/php-fpm.log
    配置pid文件:pid = /usr/local/php/var/run/php-fpm.pid
    保存退出
    cd /usr/local/php/etc/php-fpm.d
    cp www.conf.default  www.conf

    管理php-fpm配置:

    cd /usr/local/src/php-7.2.4
    cp ./sapi/fpm/php-fpm.service 到 /usr/lib/systemd/system/下

    也执行以下命令启动php-fpm服务:
    cp sapi/fpm/php-fpm.service /usr/local/php/bin/
    /usr/local/bin/php-fpm
    启动完毕之后,php-fpm服务默认使用9000端口,使用 netstat -tln | grep 9000 可以查看端口使用情况:


    配置开机启动php-fpm:
    systemctl enable php-fpm

    启动php-fpm:
    systemctl start php-fpm

    查看状态:
    systemctl status php-fpm

    添加环境变量:
    vim  /etc/profile

    在末尾追加:
    export PATH=$PATH:'/usr/local/php/bin/'

    保存退出。
    source /etc/profile

    测试:
    php -v

    看到php版本信息就表示已经成功了。


    如果需要区分web和cli环境,可以将 /usr/local/php/etc/php.ini 复制一份,重命名为php-cli.ini

    cp /usr/local/php/etc/php.ini  /usr/local/php/etc/php-cli.ini 

    需要调整配置,就在各自的配置文件中进行调整即可。


    设置nginx
    nginx配置:
    server {
    listen 80;
    server_name www.demo.com;

    #charset koi8-r;
    access_log /var/logs/nginx/access.log main;
    error_log /var/logs/nginx/error.log;

    root /wwwroot;
    location / {
    index index.php;
    try_files $uri /index.php?_RW_=$uri;
    }

    #error_page 404 /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
    root /usr/share/nginx/html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ .php$ {
    # proxy_pass http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ .php$ {
    root html;
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME /wwwroot$fastcgi_script_name;
    include fastcgi_params;
    }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /.ht {
    # deny all;
    #}
    }

    修改完这些保存并退出,然后重启nginx:
    /usr/local/nginx/nginx -s stop
    /usr/local/nginx/nginx
    或者
    /usr/local/nginx/nginx -s reload

    访问网站,如果能正常打开页面,就证明设置成功了,有些时候会遇到一些权限问题,比如我就遇到了缓存目录没有写权限,chmod 755 cache修改目录的权限,然后程序就能正常运行了。

    done!

  • 相关阅读:
    Cocos2d-x场景生命周期函数介绍
    一致性hash算法在memcached中的使用
    linux操作系统下查看某rpm包是32bit 还是x64bit的命令
    JavaScript与Java通信
    DevExpress2011控件教程)编辑控件(comboBox,AspxCheckBox) 范例1
    Tips:javascript 图片放大和取得尺寸
    Eclipse颜色主题插件-Eclipse Color Theme
    Android Fragment 详解(一)
    《火球——UML大战需求分析》(第1章 大话UML)——1.4 如何学好UML?
    java.lang.UnsatisfiedLinkError: Native method not found 三种可能解决方案
  • 原文地址:https://www.cnblogs.com/zqifa/p/centos-php7-1.html
Copyright © 2011-2022 走看看