Linux環境安裝PHP7

來源:互聯網
上載者:User

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

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.