php7-install.md
使用源碼編譯安裝PHP7
2015年6月11日,PHP官網(wǎng)發(fā)布消息,正式公開(kāi)發(fā)布PHP7第一版的alpha版本.
### PHP7特性:
PHP 7.0.0 Alpha 1使用新版的ZendEngine引擎,帶來(lái)了許多新的特性,以下是不完全列表:
(1)性能提升:PHP7比PHP5.6性能提升了兩倍。 Improved performance: PHP 7 is up
to twice as fast as PHP 5.6
(2)全面一致的64位支持。 Consistent 64-bit support
(3)以前的許多致命錯(cuò)誤,現(xiàn)在改成拋出異常。Many fatal errors are now
Exceptions
(4)移除了一些老的不在支持的SAPI(服務(wù)器端應(yīng)用編程端口)和擴(kuò)展。Removal of old and
unsupported SAPIs and extensions
(5)新增了空接合操作符。The null coalescing operator (??)
(6)新增加了結(jié)合比較運(yùn)算符。Combined comparison Operator (<=>)
(7)新增加了函數(shù)的返回類型聲明。Return Type Declarations
(8)新增加了標(biāo)量類型聲明。Scalar Type Declarations
(9)新增加匿名類。Anonymous Classes
### 系統(tǒng)環(huán)境:
```
Mac-mini:~ WangTom$ uname -mnprs
Darwin Mac-mini.local 14.3.0 x86_64 i386
Mac-mini:~ WangTom$ sw_vers
ProductName: Mac OS X
ProductVersion: 10.10.3
BuildVersion: 14D136
```
### 源碼安裝PHP7:
PHP7下載地址:https://downloads./~ab/
```
$ wget
https://downloads./~ab/php-7.0.0alpha1.tar.bz2
$ tar jxf php-7.0.0alpha1.tar.bz2
$ cd php-7.0.0alpha1
$ ./configure
... ...
checking size of long... (cached) 8
checking size of long long... (cached) 8
checking for iconv support... yes
checking for iconv... no
checking for libiconv... no
configure: error: Please specify the install prefix of iconv
with --with-iconv=
```
安裝 libiconv (字符編碼轉(zhuǎn)換庫(kù))
網(wǎng)站地址: http://www./software/libiconv/
當(dāng)前版本:
http://ftp./pub/gnu/libiconv/libiconv-1.14.tar.gz
```
$ wget
http://ftp./pub/gnu/libiconv/libiconv-1.14.tar.gz
$ tar zxf libiconv-1.14.tar.gz
$ cd libiconv-1.14
$ ./configure --prefix=/usr/local/lib/libiconv
$ make
$ sudo make install
```
配置參數(shù)
```
$ ./configure --prefix=/usr/local/php7 \
--enable-fpm \
--with-config-file-path=/usr/local/php7/etc \
--with-iconv=/usr/local/lib/libiconv \
執(zhí)行configure配置后,可以看到有如下結(jié)果:
... ...
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
WangTomdeMacBook-Pro:php-7.0.0alpha1
wangtom$
```
$ make
$ make test
$ sudo make install
查看PHP7是否安裝成功
````
WangTomdeMacBook-Pro:php-7.0.0alpha1 wangtom$
/usr/local/php7/bin/php -v
PHP 7.0.0alpha1 (cli) (built: Jun 20 2015
00:04:19)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v3.0.0-dev, Copyright (c) 1998-2015 Zend
Technologies
Mac-mini:~ WangTom$ sudo ln -s /usr/local/php7/bin/php
/usr/bin/php7
Mac-mini:~ WangTom$ php -v
PHP 5.5.20 (cli) (built: Feb 25 2015 23:30:53)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend
Technologies
Mac-mini:~ WangTom$ php7 -v
PHP 7.0.0alpha1 (cli) (built: Jun 23 2015 17:24:34)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v3.0.0-dev, Copyright (c) 1998-2015 Zend
Technologies
Mac-mini:php-fpm.d WangTom$ which php
/usr/bin/php
Mac-mini:php-fpm.d WangTom$ which php7
/usr/bin/php7
```
### 配置PHP-FPM:
Nginx不支持對(duì)外部程序的直接調(diào)用或者解析,所有的外部程序(包括PHP)必須通過(guò)FastCGI接口來(lái)調(diào)用。
PHP-FPM是一個(gè)PHP FastCGI管理器,新版的PHP已經(jīng)集成了php-fpm,在./configure的時(shí)候帶
–enable-fpm參數(shù)即可開(kāi)啟PHP-FPM.
FPM (FastCGI Process Manager) is an alternative PHP FastCGI
implementation with some additional features (mostly) useful for
heavy-loaded sites.
啟動(dòng) PHP-FPM:
```
Mac-mini:php7 WangTom$ /usr/local/php7/sbin/php-fpm
[23-Jun-2015 15:33:01] WARNING: Nothing matches the include
pattern '/usr/local/php7/etc/php-fpm.d/*.conf' from
/usr/local/php7/etc/php-fpm.conf at line 125.
[23-Jun-2015 15:33:01] ERROR: failed to open error_log
(/usr/local/php7/var/log/php-fpm.log): Permission denied (13)
[23-Jun-2015 15:33:01] ERROR: failed to post process the
configuration
[23-Jun-2015 15:33:01] ERROR: FPM initialization failed
```
提示錯(cuò)誤說(shuō)/usr/local/php7/var/log/php-fpm.log 沒(méi)權(quán)限,就給777權(quán)限:
$ chmod 777 /usr/local/php7/var/log/
修改 php-fpm 配置文件:
$ cd /usr/local/php7/etc/
$ cp php-fpm.conf.default php-fpm.conf
$ vim php-fpm.conf
修改 /usr/local/php7/etc/php-fpm.d/www.conf 文件:
如果這個(gè)文件不存在,就從default復(fù)制一份:
$ cd /usr/local/php7/etc/php-fpm.d/
$ cp www.conf.default www.conf
將配置文件中的 user 和 group 部分的 nobody 改成 www:
$ vim /usr/local/php7/etc/php-fpm.d/www.conf
開(kāi)始啟動(dòng) php-fpm:
```
Mac-mini:php-7.0.0alpha1 WangTom$
/usr/local/php7/sbin/php-fpm
[23-Jun-2015 18:30:48] NOTICE: [pool www] 'user' directive is
ignored when FPM is not running as root
[23-Jun-2015 18:30:48] NOTICE: [pool www] 'group' directive is
ignored when FPM is not running as root
[23-Jun-2015 18:30:48] ERROR: unable to bind listening socket
for address '127.0.0.1:9000': Address already in use (48)
[23-Jun-2015 18:30:48] ERROR: FPM initialization failed
```
這個(gè)錯(cuò)誤問(wèn)題有兩個(gè):(1)沒(méi)有使用root賬戶執(zhí)行啟動(dòng)命令 (2)端口9000被占用
解決方法:
使用root賬戶執(zhí)行php-fpm啟動(dòng),或 sudo /usr/local/php7/sbin/php-fpm
關(guān)閉 PHP-fpm, 并重新啟動(dòng):
```
Mac-mini:~ WangTom$ lsof -P | grep ':9000' | awk '{print $2}'
| xargs kill -9
Mac-mini:php-7.0.0alpha1 WangTom$ /usr/local/php7/sbin/php-fpm
-t
[23-Jun-2015 18:30:25] NOTICE: configuration file
/usr/local/php7/etc/php-fpm.conf test is successful
Mac-mini:~ WangTom$ sudo /usr/local/php7/sbin/php-fpm
Mac-mini:~ WangTom$
```
修改Nginx 配置:
在 nginx.conf 配置文件server 部分增加fastcgi配置,并重新加載配置文件:
```
Mac-mini:~ WangTom$ sudo vim
/usr/local/nginx/conf/nginx.conf
> location ~ \.php$ {
>
>
>
>
>
> }
Mac-mini:~ WangTom$ sudo /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf
syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf
test is successful
Mac-mini:~ WangTom$ sudo /usr/local/nginx/sbin/nginx -s
reload
Mac-mini:~ WangTom$
```
用到的一些命令:
uname: 用來(lái)獲取電腦和操作系統(tǒng)的相關(guān)信息
sw_vers: Mac下查看系統(tǒng)版本信息
lsof: 列出當(dāng)前系統(tǒng)打開(kāi)文件(list open files)
which: 指令會(huì)在環(huán)境變量$PATH設(shè)置的目錄里查找符合條件的文件
參考鏈接:
- http:///archive/2015.php#id2015-06-11-3
-
http://www./blog/compiling-and-installing-php7-ubuntu
[END]
|
|
來(lái)自: php入門(mén) > 《php》