美文网首页
PHP-7.2.2源码编译安装

PHP-7.2.2源码编译安装

作者: snowstorm | 来源:发表于2018-02-10 19:00 被阅读0次

    本次安装基于系统CentOS Linux release 7.2.1511 (Core)

    1.环境配置

    安装前的环境准备:

    ##安装make,已安装,可省略
    $yum -y install gcc automake autoconf libtool make
    ##安装gcc g++ glibc库
    $yum -y install gcc gcc-c++ glibc
    ##安装所需的包
    $yum -y install libmcrypt-devel mhash-devel libxslt-devel 
    libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel 
    zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel 
    ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel 
    krb5 krb5-devel libidn libidn-devel openssl openssl-devel
    

    安装的包有些多,以上安装可分批或者一个一个进行,如yum -y install libmcrypt-devel,一般来说均可安装成功,如果失败可多试几次。

    2.php安装

    下载源码编译安装
    ##下载源码
    $wget http://am1.php.net/distributions/php-7.2.2.tar.gz
    ##解压
    $tar -zxvf php-7.2.2.tar.gz
    ##创建安装目录
    $mkdir php7
    $mv php-7.2.2 php7
    $cd php7/php-7.2.2/
    ## 编译前配置
    $./configure --prefix=/home/test/php7 --with-config-file-path=/home/test/php7/etc --with-curl --with-freetype-dir --with-gd \
    --with-gettext --with-iconv-dir --with-kerberos --with-libdir=lib64 --with-libxml-dir --with-mysqli --with-openssl --with-pcre-regex \
    --with-pdo-mysql --with-pdo-sqlite --with-pear --with-png-dir --with-jpeg-dir --with-xmlrpc --with-xsl --with-zlib --with-bz2 \
    --with-mhash --enable-fpm --enable-bcmath --enable-libxml --enable-inline-optimization --enable-gd-native-ttf --enable-mbregex \
    --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-sysvshm \
    --enable-xml --enable-zip --with-ldap
     
    ##编译时间略长,耐心等待
    $make
    ##安装
    $make install
    
    配置php相关文件
    ##php.ini,编译配置时配在php7/etc目录下
    $cp php-7.2.2/php.ini-development ../etc/php.ini
    ##php-fpm.conf
    $cp ../etc/php-fpm.conf.default ../etc/php-fpm.conf
    ##www.conf
    $cp ../etc/php-fpm.d/www.conf.default ../etc/php-fpm.d/www.conf
    
    修改配置
    • php.ini
      cgi.force_redirect = 1被注释,需要放开且修改为cgi.force_redirect = 0
    • php-fpm.conf
      修改错误日志路径error_log = log/php-fpm.log
    • www.conf
      修改用户和用户组选项user = nginxgroup = nginx
    设置php环境变量
    $vim /etc/profile
    ##加上下面这句话
    export PATH=/home/test/php7/bin:/home/test/php7/sbin:$PATH
    
    $source /etc/profile
    $php -v
    PHP 7.2.2 (cli) (built: Feb 10 2018 16:13:50) ( NTS )
    Copyright (c) 1997-2018 The PHP Group
    Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    
    启动php
    $/home/test/php7/sbin/php-fpm
    ##检查进程是否启动
    $ps -ef | grep php
    root     41963     1  0 18:04 ?        00:00:00 php-fpm: master process (/home/test/php7/etc/php-fpm.conf)
    nginx    41964 41963  0 18:04 ?        00:00:00 php-fpm: pool www
    nginx    41965 41963  0 18:04 ?        00:00:00 php-fpm: pool www
    ##检查端口9000是否活着
    $netstat -anp | grep 9000
    tcp        0      0 127.0.0.1:9000          0.0.0.0:*               LISTEN      41963/php-fpm: mast
    

    3.修改nginx配置

    Nginx安装参考:Nginx源码安装
    找到nginx配置nginx.conf,修改如下,修改后重启nginx:

    server {
            listen       80;
            server_name  localhost;
    
            #charset koi8-r;
    
            #access_log  logs/host.access.log  main;
        
            location / {
                root   html;
                ##添加index.php
                index  index.php index.html index.htm;
            }
    
            # redirect server error pages to the static page /50x.html
            #
            error_page   500 502 503 504  /50x.html;
            location = /50x.html {
                root   html;
            }
    
             ##注意这里有关php的location注释要放开
            # 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  /home/test/nginx/html$fastcgi_script_name;
                include        fastcgi_params;
            }
    
        }
    

    4.测试

    在nginx/html目录下建文件index.php,文件内容如下

    <?php
        phpinfo();
    ?>
    

    访问 http://IP/index.php (IP为服务器的ip地址)可得如下页面即是成功

    php.png

    注意:nginx的用户对html目录必须有读写权限;最好nginx,php的用户保持统一

    附录

    php官方中文手册

    php配置选项说明

    相关文章

      网友评论

          本文标题:PHP-7.2.2源码编译安装

          本文链接:https://www.haomeiwen.com/subject/mrlhtftx.html