需求
目前需要安装php的扩展
- redis
- obcache
安装 redis
下载
wget https://pecl.php.net/get/redis-5.0.2.tgz
解压
tar -zxvf redis-5.0.2.tgz
进入扩展目录执行 phpize
/usr/local/services/7.1.8/bin/phpize
报错
Configuring for:
PHP Api Version: 20160303
Zend Module Api No: 20160303
Zend Extension Api No: 320160303
Cannot find autoconf. Please check your autoconf installation and the
$PHP_AUTOCONF environment variable. Then, rerun this script.
解决:
yum install autoconf
执行configure
./configure --with-php-config=/usr/local/services/7.1.8/bin/php-config
构建
make && make install
完毕
Installing shared extensions: /usr/local/services/php@7.1/7.1.8/lib/php/extensions/no-debug-zts-20160303/
配置
修改 php.ini 文件
extension=redis.so
安装 opcache
补充: 傻了,PHP7自带opchache扩展,不用编译安装了,php5 才需要。
下载
wget https://pecl.php.net/get/zendopcache-7.0.5.tgz
解压
tar -zxvf zendopcache-7.0.5.tgz
安装
第一步
/usr/local/services/7.1.8/bin/phpize
第二步
./configure --with-php-config=/usr/local/services/7.1.8/bin/php-config
第三步
make -j 4 && make install
错误
报错1
zend_uint key_length);
^
/usr/local/src/php/zendopcache-7.0.5/zend_accelerator_hash.h:87:3: error: unknown type name ‘zend_uint’
zend_uint key_length);
^
/usr/local/src/php/zendopcache-7.0.5/ZendAccelerator.c:39:35: fatal error: TSRM/tsrm_virtual_cwd.h: No such file or directory
#include "TSRM/tsrm_virtual_cwd.h"
原因: PHP 版本问题,编译安装官网只有PHP5的扩展版本。
配置
修改 php.ini 文件
zend_extension=opcache.so
[opcach]
; Determines if Zend OPCache is enabled
opcache.enable=1
; Determines if Zend OPCache is enabled for the CLI version of PHP
opcache.enable_cli=1
; The OPcache shared memory storage size.
opcache.memory_consumption=128
; The amount of memory for interned strings in Mbytes.
opcache.interned_strings_buffer=8
; The maximum number of keys (scripts) in the OPcache hash table.
; Only numbers between 200 and 1000000 are allowed.
opcache.max_accelerated_files=10000
清理opcache缓存工具
当然是 cachetool
工具参考: CacheTool
安装
curl -sO http://gordalina.github.io/cachetool/downloads/cachetool.phar
chmod +x cachetool.phar
使用
You can connect to a fastcgi server using an IP address
查看状态
php cachetool.phar opcache:status --fcgi=127.0.0.1:9000
清理
php cachetool.phar opcache:reset --fcgi=127.0.0.1:9000
Using the CLI
查看状态
php cachetool.phar opcache:status --cli
清理
php cachetool.phar opcache:reset --cli