http://blog.csdn.net/21aspnet/article/details/47708763
下載
# wget http://php.net/get/php-7.0.2.tar.gz/from/a/mirror
1
解壓安裝
# tar zxvf php-7.0.2.tar.gz# cd php-7.0.2
1 2
首先查看安裝協助
# ./configure --help# ./configure --prefix=/usr/local/php \ --with-curl \ --with-freetype-dir \ --with-gd \ --with-gettext \ --with-iconv-dir \ --with-kerberos \ --with-libdir=lib64 \ --with-libxml-dir \ --with-mysqli \ --with-openssl \ --with-pcre-regex \ --with-pdo-mysql \ --with-pdo-sqlite \ --with-pear \ --with-png-dir \ --with-xmlrpc \ --with-xsl \ --with-zlib \ --enable-fpm \ --enable-bcmath \ --enable-libxml \ --enable-inline-optimization \ --enable-gd-native-ttf \ --enable-mbregex \ --enable-mbstring \ --enable-opcache \ --enable-pcntl \ --enable-shmop \ --enable-soap \ --enable-sockets \ --enable-sysvsem \ --enable-xml \ --enable-zip
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
如果配置錯誤,需要安裝需要的模組,直接yum一併安裝依賴庫
# yum -y install libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel MySQL pcre-devel
1
注意:安裝php7beta3的時候有幾處配置不過去,需要yum一下,現在php-7.0.2已經不用這樣了。
# yum -y install curl-devel# yum -y install libxslt-devel
1 2
編譯安裝
# make && make install
1
設定檔
# cp php.ini-development /usr/local/php/lib/php.ini# 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 -R ./sapi/fpm/php-fpm /etc/init.d/php-fpm
1 2 3 4
需要注意的是php7中www.conf這個設定檔配置phpfpm的連接埠號碼等資訊,如果你修改預設的9000連接埠號碼需在這裡改,再改nginx的配置
啟動
# /etc/init.d/php-fpm
1
查看phpinfo()
php7和php5效能分析比較
<?php //time /usr/local/php5/bin/php search_by_key.php $a = array(); for($i=0;$i<600000;$i++){ $a[$i] = $i; } foreach($a as $i) { array_key_exists($i, $a); } ?> 1 2 3 4 5 6 7 8 9 10 11 12
產生一個 60 萬元素的數組,通過尋找key 的方式,來確定key是否存在。
PHP 5.4.44 版[root@localhost www5.4.44]# time /usr/local/php5.4.44/bin/php search_by_key.phpreal 0m0.351suser 0m0.300ssys 0m0.050sPHP 5.5.28 版[root@localhost www]# time /usr/local/php/bin/php search_by_key.phpreal 0m0.361suser 0m0.304ssys 0m0.057sPHP 7.0.0 版[root@localhost www7]# time /usr/local/php7/bin/php search_by_key.phpreal 0m0.114suser 0m0.097ssys 0m0.017s
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
很明顯php7的效能是php5的3倍。
配置opcache
官網地址:http://php.net/opcache
使用下列推薦設定來獲得較好的效能:
opcache.memory_consumption=128opcache.interned_strings_buffer=8opcache.max_accelerated_files=4000opcache.revalidate_freq=60opcache.fast_shutdown=1opcache.enable_cli=1
1 2 3 4 5 6
你也可以禁用 opcache.save_comments 並且啟用 opcache.enable_file_override。 需要提醒的是,在生產環境中使用上述配置之前,必須經過嚴格測試。 因為上述配置存在一個已知問題,它會引發一些架構和應用的異常, 尤其是在存在文檔使用了備忘註解的時候。
vim /usr/local/php7/etc/php.ini# 加入zend_extension=/usr/local/php7/lib/php/extensions/no-debug-non-zts-20141001/opcache.so
1 2 3
重啟
# killall php-fpm# /etc/init.d/php-fpm
1 2