php5.6 如何安装 opcache

原创 PHP环境 Centos
阅读数: 1029 2017年08月28日

php 5.6.16 安装 opcache 步骤


opcache 在PHP 源码包里面就有了,无需额外下载。


1、找出 php 安装路径,查找phpize的位置

# find / -name phpize

/usr/local/php/bin/phpize 


2、先进入 php 5.6.16 源码包,找到 opcache 目录

可通过 find 命令找出来:

find / -name opcache

进入:cd /web/down/lnmp1.1-full/php-5.6.16/ext/opcache


3、用 phpize 工具编译模块

/usr/local/php/bin/phpize

Configuring for:

PHP Api Version: 20131106

Zend Module Api No: 20131226

Zend Extension Api No: 220131226


4、不要切换目录,继续在当前目录下执行下面的生成配置文件 configure。

./configure --with-php-config=/usr/local/php/bin/php-config

...

...

creating libtool

appending configuration tag "CXX" to libtool

configure: creating ./config.status

config.status: creating config.h


5、编译和安装make && make install

/bin/sh /web/down/lnmp1.1-full/php-5.6.16/ext/opcache/libtool --mode=install cp ./opcache.la /web/down/lnmp1.1-full/php-5.6.16/ext/opcache/modules

cp ./.libs/opcache.so /web/down/lnmp1.1-full/php-5.6.16/ext/opcache/modules/opcache.so

cp ./.libs/opcache.lai /web/down/lnmp1.1-full/php-5.6.16/ext/opcache/modules/opcache.la

cp ./.libs/opcache.a /web/down/lnmp1.1-full/php-5.6.16/ext/opcache/modules/opcache.a

chmod 644 /web/down/lnmp1.1-full/php-5.6.16/ext/opcache/modules/opcache.a

ranlib /web/down/lnmp1.1-full/php-5.6.16/ext/opcache/modules/opcache.a

libtool: install: warning: remember to run `libtool --finish /web/down/lnmp1.1-full/php-5.6.16/modules' Build complete.

Don't forget to run 'make test'.


Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20131226/


最后它会告诉你opcache.so已经编译成功,就放在 /usr/local/php/lib/php/extensions/no-debug-non-zts-20131226/ 这个目录里


6、修改 php.ini 文件,添加配置

vim /usr/local/php/etc/php.ini


在最后面添加这个: [opcache]

zend_extension = /usr/local/php/lib/php/extensions/no-debug-non-zts-20131226/opcache.so


; 开关打开

opcache.enable=1


; 可用内存, 酌情而定, 单位 megabytes

opcache.memory_consumption=128


; interned string 的内存大小, 也可调

opcache.interned_strings_buffer=8


; 最大缓存的文件数目, 命中率不到 100% 的话, 可以试着提高这个值

opcache.max_accelerated_files=4000


; Opcache 会在一定时间内去检查文件的修改时间, 这里设置检查的时间周期, 默认为 2, 单位为秒(每次自动更新,如果文件比较大,会比较消耗 I/O)

opcache.revalidate_freq=300


; 在规定时间内,是否检查文件最后更新时间,1表示检查;0表示否,永久不检查不更新缓存,生成环境这个要关闭(每次自动更新,如果文件比较大,会比较消耗 I/O)

opcache.validate_timestamps = 0


; 是否快速关闭, 打开后在PHP Request Shutdown的时候回收内存的速度会提高

opcache.fast_shutdown=1


; 是否在CLI(即命令行时)启用opcache

opcache.enable_cli=1


; 不保存文件/函数的注释

opcache.save_comments=0


7、重启 php-fmp

/etc/init.d/php-fpm restart


完成


phpriji.cn | 网站地图 | 沪ICP备17015433号-1