在不停机下为PHP安装APC加速

根据《CentOS 6.2 上编译安装 Nginx 1.0.15 + PHP 5.3.12 + MySQL 5.1.62》一文,本机上为PHP安装了eAccelerator 0.9.6 加速器。之后,在对Discuz X2.0使用中发现其居然将APC作为一个数据缓存器,实现了类似memcache的机制,为此打算安装APC来研究一番。

首先是下载编译安装apc,使用以下命令即可

1
2
3
4
5
6
7
8
9
cd /usr/local/src
wget http://pecl.php.net/get/APC-3.1.9.tgz
tar -zxvf APC-3.1.9.tgz
cd APC-3.1.9
/usr/local/webserver/php/bin/phpize
./configure --enable-apc --enable-apc-mmap --with-php-config=/usr/local/webserver/php/bin/php-config
make
make install

然后就是修改/usr/local/webserver/php/etc/目录下的php.ini,移除其中的所有eAccelerator模块,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[eaccelerator]
zend_extension="/usr/local/webserver/php/lib/php/extensions/no-debug-non-zts-20090626/eaccelerator.so"
eaccelerator.shm_size="64"
eaccelerator.cache_dir="/usr/local/webserver/eaccelerator_cache"
eaccelerator.enable="1"
eaccelerator.optimizer="1"
eaccelerator.check_mtime="1"
eaccelerator.debug="0"
eaccelerator.filter=""
eaccelerator.shm_max="0"
eaccelerator.shm_ttl="3600"
eaccelerator.shm_prune_period="3600"
eaccelerator.shm_only="0"
eaccelerator.compress="1"
eaccelerator.compress_level="9"

接着是添加apc模块

1
2
3
4
5
6
7
8
9
extension = "apc.so"
apc.enabled = 1
apc.cache_by_default = on
apc.shm_segments = 1
apc.shm_size = 32M
apc.ttl = 3600
apc.user_ttl = 3600
apc.num_files_hint = 0
apc.write_lock = On

然后reload php即可

1
service php-fpm reload

apc-installation