歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> 在CentOS 7.x / Fedora 21上面體驗PHP 7.0

在CentOS 7.x / Fedora 21上面體驗PHP 7.0

日期:2017/2/27 15:49:25   编辑:Linux教程

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軟件包管理器安裝。以下一條命令即可完成:

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 clone https://git.php.net/repository/php-src.git
Cloning into 'php-src'...
remote: Counting objects: 615064, done.
remote: Compressing objects: 100% (127800/127800), done.
remote: Total 615064 (delta 492063), reused 608718 (delta 485944)
Receiving objects: 100% (615064/615064), 152.32 MiB | 16.97 MiB/s, done.
Resolving deltas: 100% (492063/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 page: /root/php7/usr/php/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: /root/php7/usr/php/man/man1/
page: phpize.1
page: php-config.1
Installing PEAR environment: /root/php7/usr/lib/php/
[PEAR] Archive_Tar - installed: 1.3.13
[PEAR] Console_Getopt - installed: 1.3.1
[PEAR] 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: /root/php7/usr/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, Copyright (c) 1998-2015 Zend Technologies

總結

PHP 7也添加到了remi倉庫,這個即將到來的版本主要關注執行效率的提升,它的新特性致力於使PHP較好滿足現代編程的需求和趨勢。PHP 7.0將會有許多新的特性、丟棄一些老版本的東西。
譯文:https://linux.cn/article-5501-1.html
Copyright © Linux教程網 All Rights Reserved