環(huán)境介紹
操作系統(tǒng):Centos 6.* ( 雙核4G教届、硬盤至少20G)
php 版本:7.0.8(也可去官網(wǎng)下載最新版本http://php.net/downloads.php )
一:php編譯安裝
1.1)yum 依賴包
yum -y install gcc-c++ gd libxml2-devel libjpeg-devel libpng-devel net-snmp-devel curl-devel libxslt-devel pcre-devel libjpeg libpng libxml2 libcurl4-openssl-dev libcurl-devel libcurl libmysqlclient freetype-config freetype freetype-devel unixODBC libxslt make
1.2)解壓php包
tar -zxf php-7.0.8.tar.gz
1.3)進(jìn)入php解壓包目錄下,編譯安裝
cd php-7.0.8
./configure --prefix=/usr/local/php708 --with-curl --with-gd --with-gettext --with-iconv-dir --with-kerberos --with-libdir=lib64 --with-libxml-dir --with-mysql --with-mysqli --with-openssl --with-pcre-regex --with-pdo-mysql --with-pdo-sqlite --with-pear --with-png-dir --with-freetype-dir --with-jpeg-dir --with-xmlrpc --with-xsl --with-zip --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
make && make install
1.4)配置文件及啟動(dòng)文件
cp php.ini-development /usr/local/php708/lib/php.ini
cp /usr/local/php708/etc/php-fpm.conf.default /usr/local/php708/etc/php-fpm.conf
cp /usr/local/php708/etc/php-fpm.d/www.conf.default /usr/local/php708/etc/php-fpm.d/www.conf
cp -R ./sapi/fpm/php-fpm /etc/init.d/php-fpm
/etc/init.d/php-fpm
二:php添加opcache
2.1)vim /usr/local/php708/lib/php.ini (在1731行)
#添加如下內(nèi)容
zend_extension=opcache.so
[opcache]
opcache.enable=1
opcache.enable_cli=1
opcache.memory_consumption=528
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=10000
opcache.revalidate_freq=1
opcache.fast_shutdown=1
opcache詳解:
opcache.enable=1 #是否開啟opcode緩存
opcache.enable_cli=1 #OPcache 的共享內(nèi)存大小派诬,以兆字節(jié)為單位
opcache.memory_consumption=528 #OPcache 的共享內(nèi)存大小,以兆字節(jié)為單位
opcache.interned_strings_buffer=8 #用來存儲(chǔ)臨時(shí)字符串的內(nèi)存大小聊倔,以兆字節(jié)為單位睡毒。 PHP 5.3.0 之前的版本會(huì)忽略此配置指令
opcache.max_accelerated_files=10000 #OPcache 哈希表中可存儲(chǔ)的腳本文件數(shù)量上限。
opcache.revalidate_freq=1 #檢查腳本時(shí)間戳是否有更新的周期暇赤,以秒為單位心例。 設(shè)置為 0 會(huì)導(dǎo)致針對(duì)每個(gè)請(qǐng)求, OPcache 都會(huì)檢查腳本更新鞋囊,這個(gè)配置在下文中會(huì)提到
opcache.fast_shutdown=1 #如果啟用止后,則會(huì)使用快速停止續(xù)發(fā)事件。 所謂快速停止續(xù)發(fā)事件是指依賴 Zend 引擎的內(nèi)存管理模塊 一次釋放全部請(qǐng)求變量的內(nèi)存失暴,而不是依次釋放每一個(gè)已分配的內(nèi)存塊坯门。(不太懂)
2.2)重啟php服務(wù)使之生效
killall php-fpm
/usr/local/php708/sbin/php-fpm
2.3)查看是否已成功添加
/usr/local/php708/bin/php -m