PHP 7 的編譯安裝配置教程詳解

來源:互聯網
上載者:User

php 的編譯安裝相當簡單,且每個版本差異不大,正因為如此之前版本的編譯安裝過程也可以參考,當然,需要注意的是,每個版本的編譯參數存在部分差異,以 ./configure --help 中具體描述的編譯配置參數為準。

本文中系統內容為 CentOS 7 64bit,如使用其他系統內容的,請注意在某些 依賴安裝環節 的差異。

準備工作

對於 CentOS ,yum 我向來是用作安裝大批量依賴的工具,所以,一股腦安裝這些依賴庫吧。

yum install -y gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libpng libpng-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses curl openssl-devel gdbm-devel db4-devel libXpm-devel libX11-devel gd-devel gmp-devel readline-devel libxslt-devel expat-devel xmlrpc-c xmlrpc-c-devel

當然,個別依賴庫可能需要手動編譯安裝,因此需要注意這個問題。在下文中,對於某些依賴庫、組件我會做一些說明。

除了上述依賴的,我們還需要查看 php 編譯安裝說明文檔,以確認還是否需要其他組件。

在源碼包中的 INSTALL 檔案裡,可以看到相關說明:

Prerequisite knowledge and software for compiling:
Basic Unix skills (being able to operate "make" and a C compiler)
An ANSI C compiler
A web server
Any module specific components (such as GD, PDF libs, etc.)

When building directly from Git sources or after custom modifications

you might also need:
autoconf: 2.13+ (for PHP < 5.4.0), 2.59+ (for PHP >= 5.4.0)
automake: 1.4+
libtool: 1.4.x+ (except 1.4.2)
re2c: Version 0.13.4 or newer
flex: Version 2.5.4 (for PHP <= 5.2)
bison: Version 1.28 (preferred), 1.35, or 1.75

之前我們已經安裝了 gcc 、 automake 、 autoconf 等,還需要 re2c 和 bison 這兩個。這兩個都是 PHP 的文法分析器。(突然發現寫這篇文章的 9 小時前 RE2C 發布了新的版本)。兩者的下載地址:

RE2C http://sourceforge.net/projects/re2c/files/0.15.3/re2c-0.15.3.tar.gz

BSION http://ftp.gnu.org/gnu/bison/bison-3.0.4.tar.gz

然後分別編譯安裝,這兩個編譯安裝不需要什麼特別的配置參數,很直接。

當然,還有 libmcrypt 這個東西,下載地址: ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.7.tar.gz 。這玩意兒必須的。

PHP 的編譯安裝

首先是從 github 下載源碼包: https://github.com/php/php-src/archive/php-7.0.0.tar.gz

下載後解壓,進入 PHP 源碼目錄:

tar zxvf php-7.0.0.tar.gz
cd php-src-php-7.0.0
調用 buildconf 產生 configure 檔案:

./buildconf --force
產生了 configure 檔案後,我們就需要著手開始進行編譯安裝的配置,如果你想知道有哪些編譯配置選項,僅需 ./configure --help 即可查看。

參考配置如下:

./configure \
--prefix=/usr/local/php/7.0.0 \
--with-config-file-path=/usr/local/php/7.0.0/etc \
--with-config-file-scan-dir=/usr/local/php/7.0.0/etc/conf.d \
--enable-fpm \
--with-fpm-user=web \
--with-fpm-group=www \
--enable-soap \
--with-openssl \
--with-openssl-dir \
--with-mcrypt \
--with-pcre-regex \
--with-zlib \
--with-iconv \
--with-bz2 \
--enable-calendar \
--with-curl \
--with-cdb \
--enable-dom \
--enable-exif \
--with-pcre-dir \
--enable-ftp \
--with-gd \
--with-jpeg-dir \
--with-png-dir \
--with-freetype-dir \
--with-gettext \
--with-gmp \
--with-mhash \
--enable-mbstring \
--with-libmbfl \
--with-onig \
--enable-pdo \
--with-pdo-mysql \
--with-zlib-dir \
--with-readline \
--enable-session \
--enable-shmop \
--enable-simplexml \
--enable-sockets \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
--enable-wddx \
--with-libxml-dir \
--with-xsl \
--enable-zip \
--enable-mysqlnd \
--with-mysqli \
--without-pear
配置執行完畢後,執行編譯安裝:

make && make install
大功告成!現在只需要將 /usr/local/php/7.0.0/bin 中的可執行檔軟串連到 /bin 下即可,當然也可以自行選擇 PATH 環境變數指定的路徑中,這樣就可以全域訪問 PHP 解析執行器了。

完成後,執行 php -v 輸出:

PHP 7.0.0 (cli) (built: Dec  3 2015 11:29:49) ( NTS )
Copyright (c) 1997-2015 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2015 Zend Technologies

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.