首先,我們的CentOS版本信息如下:

開始我們的編譯。
第一步:
將php安裝包安裝到/usr/src目錄下。
|
1
|
cd
/usr/src
&& wget http:
//cn2
.php.net
/distributions/php-7
.2.3.
tar
.gz
|

第二步:
加壓這個壓縮包
tar -xzxvf php-7.2.3.tar.gz

第三步:
進入壓縮后的文件目錄。安裝如下文件,如果已經安裝也沒問題,系統會提示已經安裝,nothing to do。
cd php-7.2.3/
yum install gcc
yum install libxml2-devel
yum install libxml2-devel




第四步:
執行以下命令(編譯的配置參數)
'./configure' '--prefix=/usr/local/php' '--with-pdo-pgsql' '--with-zlib-dir' '--with-freetype-dir' '--enable-mbstring' '--with-libxml-dir=/usr' '--enable-soap' '--enable-calendar' '--with-curl' '--with-mcrypt' '--with-gd' '--with-pgsql' '--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-pdo-mysql' '--with-mysqli' '--with-jpeg-dir=/usr' '--with-png-dir=/usr' '--enable-gd-native-ttf' '--with-openssl' '--with-fpm-user=www-data' '--with-fpm-group=www-data' '--with-libdir=/lib/x86_64-linux-gnu/' '--enable-ftp' '--with-gettext' '--with-xmlrpc' '--with-xsl' '--enable-opcache' '--enable-fpm' '--with-iconv' '--with-xpm-dir=/usr'

最后一行會出現錯誤提示:configure: error: Cannot find OpenSSL's <evp.h>
未發現openssl,我們安裝就好。
yum install openssl openssl-devel
出現Complete!則表示安裝完成
繼續以上命令出現錯誤提示: configure: error: Please reinstall the BZip2 distribution
安裝即可
yum install bzip2-devel.x86_64 -y
仔細看還有錯誤:configure: WARNING: This bison version is not supported for regeneration of the Zend/PHP parsers (found: none, min: 204, excluded: ).
安裝即可
wget http://ftp.gnu.org/gnu/bison/bison-2.4.1.tar.gz tar -zxvf bison-2.4.1.tar.gz cd bison-2.4.1/ ./configure
提示錯誤:configure: error: GNU M4 1.4 is required
未安裝m4
yum install m4
再重新編譯上面的make clean && make install
安裝完成后切入php目錄
繼續配置checking發現錯誤:configure: WARNING: unrecognized options: --with-mcrypt, --enable-gd-native-ttf
這個是由於php7.2是 17年11月份發行的,在php7.1時,
官方就開始建議用openssl_*系列函數代替Mcrypt_*系列的函數。
所以我們刪除這兩項即可。
然后繼續發現錯誤:configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.
解決:
wget https://sourceforge.net/projects/re2c/files/0.16/re2c-0.16.tar.gz tar zxf re2c-0.16.tar.gz && cd re2c-0.16 ./configure
make && make install
如果出現錯誤:configure: error: C++ compiler cannot create executables
就是gcc擴展沒裝全。
yum install gcc gcc-c++ gcc-g77
至此,再測試,發現已無報錯。
當你進行 make時候發現:No targets specified and no makefile found. Stop.
則需要進行一下方案解決:
#拿到安裝包 wget http://ftp.gnu.org/pub/gnu/ncurses/ncurses-5.6.tar.gz #解壓 tar zxvf ncurses-5.6.tar.gz #指向php的路徑 ./configure -prefix=/usr/src/php-7.2.3 #開始make make && make install
此時,我們再去/usr/src/php-7.2.3目錄下make && make install。
這時候 我們輸入php -v可以看到php的版本。

但是,我們一般還需要做一個配置。讓php成為一個服務。並且開機自啟。
但是卻發現php-fpm不知道咋哪里。 那我們就應該安裝php-fpm.
#找找php-fpm find / -name php-fpm.conf #沒找到就安裝 yum install php-fpm php-mysql

做如下的配置
mkdir -p /usr/local/php/etc/ touch /usr/local/php/etc/php-fpm.conf cp /etc/php-fpm.conf /usr/local/php/etc/php-fpm.conf
同樣道理
mkdir -p /usr/local/php/etc/php-fpm.d/ touch /usr/local/php/etc/php-fpm.d/www.conf cp /etc/php-fpm.d/www.conf /usr/local/php/etc/php-fpm.d/www.conf
繼續
mkdir -p /etc/init.d touch /etc/init.d/php-fpm cp /usr/src/php-7.2.3/sapi/fpm/init.d.php-fpm.in /etc/init.d/php-fpm
啟動服務並查看
service php-fpm start ps aux | grep php-fpm
此時我們的php編譯就大功告成。
如下:


