服務架設-CentOS7下編譯安裝 PHP7

Centos7.2 編譯安裝PHP7

PHP7,編譯安裝:

環境:centos7.2 (注意:因為我用的nginx, 此配置參數沒有考慮到apache,所以不合適需要用apache的朋友照搬過去運行,但是可以參考。)

直接下載PHP7.0.2的安裝包解壓,編譯,安裝:
下載php7,并解壓

$ cd /usr/src/
$ wget http://cn2.php.net/distributions/php-7.0.2.tar.gz
#解壓
$ tar -xzxvf php-7.0.2.tar.gz
$ cd php-7.0.2

解壓完后先不要編譯,請檢查是否安裝了gcc ,沒有的話執行yum install gcc

檢查是否安裝了libxml2 ,沒有的話執行yum install libxml2

檢查是否安裝了libxml2-devel,沒有的話執行yum install libxml2-devel

注:因為改為用nginx了,所以編譯參數中的--with-apxs2=/usr/bin/apxs去掉了,如果要配置apache用,安裝PHP前,請先安裝apache。

編譯參數配置

    './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'

出現報錯 Cannot find OpenSSL's <evp.h>
則執行 yum install openssl openssl-devel

出現報錯 Please reinstall the libcurl distribution
則執行
yum -y install curl-devel

出現報錯 jpeglib.h not found
則執行

yum install libjpeg.x86_64 libpng.x86_64 freetype.x86_64 libjpeg-devel.x86_64 libpng-devel.x86_64 freetype-devel.x86_64 -y

和執行

yum install libjpeg-devel

checking for BZip2 in default path... not found
configure: error: Please reinstall the BZip2 distribution
這是bzip2軟件包沒有安裝
解決辦法
yum install bzip2-devel.x86_64 -y

configure: error: xpm.h not found.

yum install libXpm-devel

error: Unable to locate gmp.h
Fix:

yum install gmp-devel

現象:Unable to detect ICU prefix or /usr//bin/icu-config failed. Please verify ICU install
prefix and make sure icu-config works
解決辦法:

  yum install -y icu libicu libicu-devel

錯誤:mcrypt.h not found. Please reinstall libmcrypt.
解決辦法:

  yum  install  php-mcrypt  libmcrypt  libmcrypt-devel

在這里我遇到了一個問題,無法正確安裝php-mcrypt,解決方法如下:

1、安裝第三方yum源

wget http://www.atomicorp.com/installers/atomic

sudo sh ./atomic

2、使用yum命令安裝

sudo yum install PHP-mcrypt

sudo yum install libmcrypt

sudo yum install libmcrypt-devel

錯誤: configure: error: Cannot find libpq-fe.h. Please specify correct PostgreSQL installation path
解決辦法:

yum install  postgresql-devel

錯誤 : configure: error: xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution
解決:

yum install libxslt-devel

配置的checking 結束后,執行:

make clean && make && make install

安裝完成后,我們要把源碼包中的配置文件復制到PHP安裝目錄下,源碼包中有兩個配置 php.ini-development php.ini-production ,看名字就知道,一個是開發環境,一個是生產環境,我們這里就復制開發環境的

cp php.ini-development /usr/local/php/lib/php.ini

另外還需要設置環境變量 :
修改/etc/profile文件使其永久性生效,并對所有系統用戶生效,在文件末尾加上如下兩行代碼
PATH=$PATH:/usr/local/php/bin
export PATH
然后執行 命令 source /etc/profile

php -v 就可以看到PHP版本信息了。

此時還需要配置PHP-fpm:


    cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
 
    cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
 
    cp /usr/src/php-7.0.2/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
 
    chmod +x /etc/init.d/php-fpm

啟動php-fpm:

/etc/init.d/php-fpm start

如果出現錯誤:ERROR: [pool www] cannot get uid for user 'www-data'
則新建www-data 用戶組:

groupadd www-data
useradd -g www-data www-data

然后再啟動php-fpm

然后安裝nginx

yum install nginx

原文地址 原文地址:

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容