在 CentOS 7.x / Fedora 21 上面体验 PHP 7.0

PHP是一种为我们熟知的通用服务器网页脚本语言。非常多的在线网站都是用PHP编写的。PHP这些年来一直在持续进化,丰富其功能,变得易于使用,更好地组织的脚本语言。目前PHP的开发团队正筹备下一个PHP版本的发行,名字是PHP 7。现在的PHP版本为PHP 5.6,可能你清楚PHP 6已经流产了,PHP 7的支持者们不希望下一个重要的版本被其他分支混淆,即过去已经停止很久的PHP 6。所以决定下一个PHP主要的发行版本叫PHP 7,而不是PHP 6。PHP 7.0预计在今年十一月份发行。

在下一代主要PHP版本里有一些不错的功能

  • 为了改善执行效率与内存占用,新的版本添加PHPNG功能
  • 引入了JIT引擎来动态编译Zend操作码为自然机器码,以此来达到更快的处理性能。这项功能允许随后的程序调用同一份代码,这样会运行快很多。
  • AST(抽象语法树)是最新添加功能,它可以增强支持PHP的扩展性和用户应用。
  • 添加异步编程功能支持一个请求中的并行任务。
  • 新的版本会支持独立的多线程网页服务器,这样可以使用一个单独的存储池处理很多并发的请求。

在CentOS/Fedora上安装PHP 7

让我们来看看怎样在CentOS 7和Fedora 21安装PHP7。为了安装PHP7,我们首先需要克隆PHP-src 仓库。当克隆工作完成,我们再配置和编译它。进行下一步之前,我们要确保已经在LInux系统下安装了如下的组件,否则PHP编译会返回错误中止。

  • Git
  • autoconf
  • gcc
  • bison

所有上面提到的要求可以使用Yum软件包管理器安装。以下一条命令即可完成:

 
 
  1. yum install git autoconf gcc bison

准备好开始安装PHP7了吗?让我们先创建一个PHP7目录,作为你的当前工作目录。

mkdir PHP7 
  
  • cd PHP7
  • 现在克隆PHP-src仓库,在终端里运行下面的命令。

    git clone https://git.PHP.net/repository/PHP-src.git 
      
     

    工作应该会在几分钟后完成,这里是一个样例输出,你应该会在任务完成时看见。

    [root@localhost PHP7]# //git.PHP.net/repository/PHP-src.git 
      
  • cloning into 'PHP-src'...
  • remote: Counting objects: 615064, done.
  • Compressing objects: 100% (127800/127800),100);">done.
  • Total 615064 (delta 492063), reused 608718 (delta 485944)
  • Receiving objects: 615064/615064), 152.32 MiB | 16.97 MiB/s,100);">done.
  • Resolving deltas: 492063/done.
  • 让我们来配置,编译PHP7,在终端运行下面的命令,开始配置工作:

    cd PHP-src 
      
  • ./buildconf
  • 下面是./buildconf命令的样例输出

    [root@localhost PHP-src]# ./buildconf 
      
  • buildconf: checking installation...
  • buildconf: autoconf version 2.69 (ok)
  • rebuilding aclocal.m4
  • rebuilding configure
  • rebuilding main/PHP_config.h.in
  • 使用下面的命令,继续配置进程:

    ./configure \ 
      
  • --prefix=$HOME/PHP7/usr \
  • --with-config-file-path=$HOME/PHP7/usr/etc \
  • --enable-mbstring \
  • --enable-zip \
  • --enable-bcmath \
  • --enable-pcntl \
  • --enable-ftp \
  • --enable-exif \
  • --enable-calendar \
  • --enable-sysvmsg \
  • --enable-sysvsem \
  • --enable-sysvshm \
  • --enable-wddx \
  • with-curl \
  • with-mcrypt \
  • with-iconv \
  • with-gmp \
  • with-pspell \
  • with-gd \
  • with-jpeg-dir=/usr \
  • with-png-dir=/usr \
  • with-zlib-dir=/usr \
  • with-xpm-dir=/usr \
  • with-freetype-dir=/usr \
  • with-t1lib=/usr \
  • --enable-gd-native-ttf \
  • --enable-gd-jis-conv \
  • with-openssl \
  • with-MysqL=/usr \
  • with-pdo-MysqL=/usr \
  • with-gettext=/usr \
  • with-zlib=/usr \
  • with-bz2=/usr \
  • with-recode=/usr \
  • with-MysqLi=/usr/bin/MysqL_config
  • 这会花去不少的时间,当完成后你应该会看到如下面的输出

    creating libtool 
      
  • appending configuration tag "CXX" to libtool
  • Generating files
  • configure: creating ./config.status
  • creating main/internal_functions.c
  • creating main/internal_functions_cli.c
  • +--------------------------------------------------------------------+
  • | License: |
  • This software is subject to the PHP License, available in this |
  • | distribution in the file LICENSE. By continuing this installation |
  • | process, you are bound by the terms of this license agreement. |
  • If you do not agree with the terms of this license, you must abort |
  • | the installation process at this point. |
  • +--------------------------------------------------------------------+
  • Thank you for using PHP.
  • config.status: creating PHP7.spec
  • config.status: creating main/build-defs.h
  • config.status: creating scripts/PHPize
  • config.status: creating scripts/man1/PHPize.1
  • config.status: creating scripts/PHP-config
  • config.status: creating scripts/man1/PHP-config.1
  • config.status: creating sapi/cli/PHP.1
  • config.status: creating sapi/cgi/PHP-cgi.1
  • config.status: creating ext/phar/phar.1
  • config.status: creating ext/phar/phar.phar.1
  • config.status: creating main/PHP_config.h
  • config.status: executing default commands
  • 运行下面的命令,完成编译过程。

    make 
      
     

    “make”命令的样例输出如下所示:

    Generating phar.PHP 
      
  • Generating phar.phar
  • PEAR package PHP_Archive not installed: generated phar will require PHP's phar extension be enabled.
  • clicommand.inc
  • directorytreeiterator.inc
  • directorygraphiterator.inc
  • pharcommand.inc
  • invertedregexiterator.inc
  • phar.inc
  • Build complete.
  • Don't forget to run 'make test'.
  • 活儿干完了,该安装PHP7了,运行下面的命令安装它。

    make install 
      
     

    成功安装的进程的样例输出应该像这样:

    [root@localhost PHP-src]# make install 
      
  • Installing shared extensions: /root/PHP7/usr/lib/PHP/extensions/no-debug-non-zts-20141001/
  • Installing PHP CLI binary: /root/PHP7/usr/bin/
  • Installing PHP CLI man page: /root/PHP7/usr/PHP/man/man1/
  • Installing PHP CGI binary: /root/PHP7/usr/bin/
  • Installing PHP CGI man/man1/
  • Installing build environment: /root/PHP7/usr/lib/PHP/build/
  • Installing header files: /root/PHP7/usr/include/PHP/
  • Installing helper programs: /root/PHP7/usr/bin/
  • program: PHPize
  • program: PHP-config
  • Installing man pages: man/man1/
  • page: PHPize.page: PHP-config.Installing PEAR environment: /root/PHP7/usr/lib/PHP/
  • [PEAR] Archive_Tar - installed: 1.3.13
  • Console_Getopt - installed: Structures_Graph- installed: 1.0.4
  • [PEAR] XML_Util - installed: 1.2.3
  • [PEAR] PEAR - installed: 1.9.5
  • Wrote PEAR system config file at: /root/PHP7/usr/etc/pear.conf
  • You may want to add: /root/PHP7/usr/lib/PHP to your PHP.ini include_path
  • /root/PHP7/PHP-src/build/shtool install -c ext/phar/phar.phar /root/PHP7/usr/bin
  • ln -s -f /root/PHP7/usr/bin/phar.phar /root/PHP7/usr/bin/phar
  • Installing PDO headers: include/PHP/ext/pdo/
  • 恭喜你,PHP7已经安装在你的Linux系统上了。安装完后,进入PHP7安装文件里的sapi/cli里面。

    cd sapi/cli 
      
     

    验证一下PHP的版本。

    [root@localhost cli]# ./PHP -v 
      
  • PHP 7.0.0-dev (cli) (built: Mar 28 2015 00:54:11)
  • copyright (c) 1997-2015 The PHP Group
  • Zend Engine v3.0.0-dev, 1998-Technologies
  • 相关文章

    Centos下搭建性能监控Spotlight
    CentOS 6.3下Strongswan搭建IPSec VPN
    在CentOS6.5上安装Skype与QQ
    阿里云基于centos6.5主机VPN配置
    CentOS 6.3下配置multipah
    CentOS安装、配置APR和tomcat-native